static int ElementSum(int [] arr, int in1, int in2)
return arr[in1] + arr[in2];
public static void Main()
int[] intArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for(int i = 0; i < intArray.Length; i++)
Console.Write(intArray[i] + " ");
Console.WriteLine("\nДлина массива: " + intArray.Length);
Console.WriteLine("Введите порядковые номера двух слагаемых");
int index1 = Convert.ToInt32(Console.ReadLine());
int index2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Сумма элементов: " + intArray[index1]
+ " + " + intArray[index2] + " = " + (ElementSum(intArray, index1, index2)));
catch(IndexOutOfRangeException)
Console.WriteLine("Индекс вне диапазона массива");
Console.WriteLine("Введите число");