c# - Find sum of 2 largest numbers in a list of integers -
in c#, need pick max value in array , sum next least value.
expected output 5+4
tried couple of syntax in foreach, couldn't exact output. looking help
int[] arr =new int[] {1,2,3,4,5}; foreach (int in arr) { }
some linq following should solve it:
arr.orderbydescending(z=>z).take(2).sum() note sorting slow, may want find max twice instead...
Comments
Post a Comment