I have
List<string> selectedOptions;
Dictionary<string,string> masterList;
masterList comprises of Keys, which are the superset for the values in selectedoptions.
Now, I would like to extract all the Values for the intersecting Keys between selectedOptions and masterList.
How would the LINQ query be framed?
or of course
but this will bomb if keys don’t exist.
you could fix this with a
Where(k => dic.ContainsKey(k))clause:After trawling the Linq source, I think that the last method is probably most efficient. Doing a join forces linq to make a
Lookup(effectively a multi-entry hashtable) over one of the collections involved in the join. Seeing as we already have a Dictionary which offers the same lookup performance as aLookup, building aLookupis superfluous.