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
Post a Comment