How to select multiple values from a Dictionary using Linq as simple as possible

前端 未结 3 857
-上瘾入骨i
-上瘾入骨i 2021-02-02 07:43

I need to select a number of values (into a List) from a Dictionary based on a subset of keys.

I\'m trying to do this in a single line of code using Linq but what I have

3条回答
  •  野的像风
    2021-02-02 08:09

    If you know that all the value that you want to select are in the dictionary, you can loop through the keys instead of looping through the dictionary:

    List selectedValues = keysToSelect.Select(k => dictionary1[k]).ToList();
    

提交回复
热议问题