Assign value of myInt using pointer : Pointer : Unsafe C# Examples


C# Examples » Unsafe » Pointer »

 

Assign value of myInt using pointer









    
using  System;
using  System.Globalization;


public  class  MainClass{
    public  static  void  SomeUnsafeCode()
    {
        unsafe
        {
            int  myInt;
            int*  ptrToMyInt  =  &myInt;
            
            //  Assign  value  of  myInt  using  pointer.
            *ptrToMyInt  =  123;    

            //  print  out  address.
            Console.WriteLine("Value  of  myInt  {0}",  myInt);
            Console.WriteLine("Address  of  myInt  {0:X}",  (int)ptrToMyInt);
        }
    }

    static  void  Main(string[]  args)
    {
                SomeUnsafeCode();
    }
}
    
   
  
   



Output

Value of myInt 123
Address of myInt 12F474


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Unsafe
» Pointer