Use fixed to put address of value into a pointer : Pointer : Unsafe C# Examples


C# Examples » Unsafe » Pointer »

 

Use fixed to put address of value into a pointer









    
using  System;  
  
class  MyClass  {  
    public  int  num;  
    public  MyClass(int  i)  {  num  =  i;  }  
}  
  
class  FixedCode  {  
    unsafe  public  static  void  Main()  {  
        MyClass  o  =  new  MyClass(19);  
  
        fixed  (int*  p  =  &o.num)  {    
  
            Console.WriteLine("Initial  value  of  o.num  is  "  +  *p);  
      
            *p  =  10;  //  assign  the  to  count  via  p  
          
            Console.WriteLine("New  value  of  o.num  is  "  +  *p);  
        }  
    }  
}
    
   
  
   



Output

Initial value of o.num is 19
New value of o.num is 10


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Unsafe
» Pointer