View Code
static void FindTwoMins(int[] intArr, ref int firstMin, ref int secondMin) { if (intArr == null || intArr.Length <2) { throw new Exception("Input array can't be empty or less than 2"); } if (intArr[0]> intArr[1]) { firstMin = intArr[1]; secondMin = intArr[0]; } else { firstMin = intArr[0]; secondMin = intArr[1]; } for (int i = 2; i < intArr.Length; i++) { if (intArr[i]<secondMin) { if (intArr[i]<firstMin) { secondMin = firstMin; firstMin = intArr[i]; } else { secondMin = intArr[i]; } } } if (firstMin == secondMin) { throw new Exception("No the second min numbers"); } }