Find next record in a set: LINQ

后端 未结 3 1660
遇见更好的自我
遇见更好的自我 2020-12-29 09:27

I have a list of objects which all have an id property

E.g

1, 10, 25, 30, 4

I have a currentId and I need to find the next Id in the list

So

3条回答
  •  一个人的身影
    2020-12-29 09:57

    int currentId = 25;
    var next = yourCollection.Where(i => i.Id > currentId).OrderBy(i => i.Id).First();
    

提交回复
热议问题