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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -