Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | None | 0 0
  1. public static int TheSecondMax()
  2.   {
  3.       List<int> myList = new List<int>() { 10, 20, 8, 20, 9, 5, 20, 10 };
  4.       int max = int.MinValue;
  5.       int secondMax = int.MinValue;
  6.       foreach (var item in myList)
  7.       {
  8.           if (item > max)
  9.           {
  10.               max = item;
  11.           }
  12.  
  13.           if (item > secondMax && item < max)
  14.           {
  15.               secondMax = item;
  16.           }
  17.       }
  18.  
  19.       return secondMax;
  20.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement