Index pointer : Pointer : Unsafe C# Examples


C# Examples » Unsafe » Pointer »

 

Index pointer









    
using  System;  
  
class  MainClass  {  
    unsafe  public  static  void  Main()  {  
        int[]  nums  =  new  int[10];  
  
        
        Console.WriteLine("Index  pointer  like  array.");  
        fixed  (int*  p  =  nums)  {  
            for(int  i=0;  i  <  10;  i++)    
                p[i]  =  i;  //  index  pointer  like  array  
  
            for(int  i=0;  i  <  10;  i++)    
                Console.WriteLine("p[{0}]:  {1}  ",  i,  p[i]);  
        }  
  
    }  
}
    
   
  
   



Output

Index pointer like array.
p[0]: 0
p[1]: 1
p[2]: 2
p[3]: 3
p[4]: 4
p[5]: 5
p[6]: 6
p[7]: 7
p[8]: 8
p[9]: 9


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Unsafe
» Pointer