Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jsauve
Created October 24, 2017 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsauve/17cab7d3379348c3141c8395a19da12a to your computer and use it in GitHub Desktop.
Save jsauve/17cab7d3379348c3141c8395a19da12a to your computer and use it in GitHub Desktop.
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