Find the item with the lowest value of a property within a list

后端 未结 4 2043
你的背包
你的背包 2021-01-18 00:45

Let\'s say I have this class:

class Person {
   public int ID;
   public string Name;
}

And then I have a list of Person\'s.



        
4条回答
  •  耶瑟儿~
    2021-01-18 01:10

    this is without sorting the list and just iterates the list once.

    Person minIdPerson = persons[0];
    foreach (var person in persons)
    {
        if (person.ID < minIdPerson.ID)
            minIdPerson = person;
    }
    

提交回复
热议问题