Home > DeveloperSection > Forums > How can I convert IEnumerable<T> to List<T> in C#?
ben reitman
ben reitman

Total Post:96

Points:676
Posted on    November-14-2013 1:09 AM

 C# C# 
Ratings:


 1 Reply(s)
 1851  View(s)
Rate this:

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

Dictionary<Guid, Record> dict = GetAllRecords();

List<Record> searchResults = new List<Record>();

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

foreach (Record rec in matches)

    searchResults.Add(rec);

myListView.DataSource = searchResults;

myListView.DataBind();



Pravesh Singh

Total Post:411

Points:2881
Posted on    November-14-2013 1:12 AM

Hi Ben,

Try this:

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



Don't want to miss updates? Please click the below button!

Follow MindStick