IntPtrs and unsafe bit-twiddling : Pointer : Unsafe C# Examples


C# Examples » Unsafe » Pointer »

 

IntPtrs and unsafe bit-twiddling





Pointers are variables that hold the addresses of other variables.




    
using  System;
using  System.IO;
using  System.Reflection;
using  System.Runtime.ConstrainedExecution;
using  System.Runtime.InteropServices;
using  Microsoft.Win32.SafeHandles;

public  class  MainClass
{
        public  unsafe  static  void  Main()
        {
                int  a  =  10;
                Console.WriteLine("a  is  {0}  ({0:X})",  a);
                IntPtr  ip  =  new  IntPtr(&a);
                byte*  pTarget  =  (byte*)ip.ToPointer()  +  1;
                *pTarget  =  2;

                Console.WriteLine("a  is  {0}  ({0:X})",  a);
        }
}
    
   
  
   



Output

a is 10 (A)
a is 522 (20A)


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Unsafe
» Pointer