Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private static IEnumerable<KeyValuePair<TKey,TValue>> RemoveByKey<TKey,TValue>(
this IEnumerable<KeyValuePair<TKey,TValue>> pairs,
string key)
{
var index = pairs.Select(x => x.Key).ToList().FindIndex(x => x.Equals(key));
if (index >= 0)
{
var result = pairs.ToList();
result.RemoveAt(index);
return result;
}
return pairs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment