public static void Main()
var result = SecondLargest(new int [] {1,4,5,5,7,});
Console.WriteLine(result);
Console.WriteLine(ex.Message);
public static int SecondLargest(int[] numbers)
throw new ArgumentException("The length of the array is less than two.");
int first = int.MinValue, second = int.MinValue;
foreach (var num in numbers)
else if(num > second && num < first)
return second == int.MinValue ? throw new InvalidOperationException("No second largest element found.") : second;