Get Max value from List

后端 未结 8 414
猫巷女王i
猫巷女王i 2021-02-02 05:08

I have List List, my type contains Age and RandomID

Now I want to find the maximum age from this list.

What

相关标签:
8条回答
  • 2021-02-02 05:48

    How about this way:

    List<int> myList = new List<int>(){1, 2, 3, 4}; //or any other type
    myList.Sort();
    int greatestValue = myList[ myList.Count - 1 ];
    

    You basically let the Sort() method to do the job for you instead of writing your own method. Unless you don't want to sort your collection.

    0 讨论(0)
  • 2021-02-02 05:53
    var maxAge = list.Max(x => x.Age);
    
    0 讨论(0)
提交回复
热议问题