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
Post a Comment