Demonstrate an array overrun : Array Index : Data Structure C# Examples


C# Examples » Data Structure » Array Index »

 

Demonstrate an array overrun









    
using  System;  
  
class  MainClass  {    
    public  static  void  Main()  {    
        int[]  sample  =  new  int[10];  
        int  i;    
    
        //  generate  an  array  overrun  
        for(i  =  0;  i  <  100;  i  =  i+1)    
            sample[i]  =  i;  
    }    
}
    
   
  
   



Output

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 Data Structure
» Array Index