How to get the second highest number in an array in Visual C#?

后端 未结 9 1799
误落风尘
误落风尘 2020-12-17 05:40

I have an array of ints. I want to get the second highest number in that array. Is there an easy way to do this?

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-17 06:04

    Try this (using LINQ):

    int secondHighest = (from number in numbers
                         orderby number descending
                         select number).Skip(1).First();
    

提交回复
热议问题