Get Max value from List

后端 未结 8 588
猫巷女王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 myList = new List(){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.

提交回复
热议问题