An unhandled exception : Exception : Language Basics C# Examples


C# Examples » Language Basics » Exception »

 

An unhandled exception









    
using  System;

class  MainClass
{

    public  static  void  Main()
    {

        int[]  myArray  =  new  int[2];
        Console.WriteLine("Attempting  to  access  an  invalid  array  element");
        myArray[2]  =  1;

    }

}
    
   
  
   



Output

Attempting to access an invalid array element

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at MainClass.Main()


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Exception