c# - How can I move next/previous in List using LINQ? -


i have class :

public class city {     public city()     {         //         // todo: add constructor logic here         //     }     public int id { get; set; }     public string title { get; set; }     public string description { get; set; }     public string image { get; set; } } 

and list :

list<city> list = new list<city>(){ new city{id=1,title="city1",description=""}, new city{id=2,title="city2",description=""}, new city{id=3,title="city3",description=""}, new city{id=4,title="city4",description=""}  } 

how can move next or move previous in list using linq ?

you want elementat, it's logically equivalent using list indexer property, , potentially far faster using skip & take @ runtime contains specific check see if sequence implements ilist, if uses indexer, if not iterates on sequence (similar doing skip(n).take(1))

var namelist = list<string>{"homer", "marge", "bart", "lisa", "maggie"}; ienumerable<string> namesequence = namelist;  secondfromlist = namelist[1]; secondfromsequence = namesequence.elemenetat(1); 

hope clear enough.

nb: ilist implemented sorts of collections, arrays etc not list<>


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -