c# - Getting keyValuePair based on filtering of keys -


i use mydictionary.keys.where sequence returns keys (my predicate imposes conditions on keys). need associated values , not sure how easily, sure miss basic functionality..

var dict = new dictionary<string, long>(); 

something like:

ienumerable<long> myvalues = dict.where(x => x.key == "a" || x.key == "b")                                  .select(x => x.value); 

that return values wanted

or

ienumerable<keyvaluepair<string, long>> myvalues = dict.where(x => x.key == "a" || x.key == "b"); 

the last return full keyvaluepair<string, long>, 2 properties (key , value)

another (slower) solution:

ienumerable<long> myvalues = dict.keys.where(x => x == "a" || x == "b")                                       .select(x => dict[x]); 

it slower because after filtering lookup dictionary keys found.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -