You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
943 B
C#

/*
* C# Program to Demonstrate IndexOutOfRange Exception
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace differnce
{
class arrayoutofindex
{
public void calculatedifference()
{
int difference=0;
int [] number= new int[5] {1,2,3,4,5};
try
{
for (int init =1; init <=5; init++)
{
difference= difference - number[init];
}
Console.WriteLine("The difference of the array is:" + difference);
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine(e.Message);
}
}
}
class classmain
{
static void Main(string [] args)
{
arrayoutofindex obj = new arrayoutofindex();
obj.calculatedifference();
Console.ReadLine();
}
}
}