How can I convert IEnumerable to List in C#?

前端 未结 5 1825
被撕碎了的回忆
被撕碎了的回忆 2020-12-29 07:14

I am using LINQ to query a generic dictionary and then use the result as the datasource for my ListView (WebForms).

Simplified code:

Dictionary

        
5条回答
  •  醉酒成梦
    2020-12-29 07:52

    Try this:

    var matches = dict.Values.Where(rec => rec.Name == "foo").ToList();
    

    Be aware that that will essentially be creating a new list from the original Values collection, and so any changes to your dictionary won't automatically be reflected in your bound control.

提交回复
热议问题