While it looks like this question that LINQ gave me for part of my problem, I am missing something similar, which should be obvious in order to avoid the last step of the loop through the dictionary.
I have a dictionary, and I want to get a list of keys only for elements for which the value is true. Now I am doing this:
Dictionary<long,bool> ItemChecklist; ... var selectedValues = ItemChecklist.Where(item => item.Value).ToList(); List<long> values = new List<long>(); foreach (KeyValuePair<long,bool> kvp in selectedValues) { values.Add(kvp.Key); }
Is there a way I can go directly to List<long> without doing this loop?
source share