c# - Creating List from Linq filter -


i'm filtering out list populated json data :

list<rootobject> flighttimes = (list<rootobject>)gridview1.datasource; foreach (var v in p in flighttimes                   p.direction == "a"                   select new { p.date, p.time, p.sorttime, p.direction, p.flightnumber, p.endpoint, p.status, p.status2 }) ; 

i'm having trouble trying data foreach new list. can this?

the problem loop produces elements of anonymous type, cannot declare typed list it. can solve problem not using foreach, , sending results of query tolist:

var mylist = (     p in flighttimes     p.direction == "a"     select new {         p.date     ,   p.time     ,   p.sorttime     ,   p.direction     ,   p.flightnumber     ,   p.endpoint     ,   p.status     ,   p.status2     } ).tolist(); 

now compiler has enough information capture type of list, producing result expect. if need perform additional processing in loop, use mylist in separate foreach loop.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -