The & is a unary operator that returns the memory address of its operand : Pointer : Unsafe C# Examples


C# Examples » Unsafe » Pointer »

 

The & is a unary operator that returns the memory address of its operand









    
using  System;

class  MainClass
{
    static  unsafe  void  print(  char*  p,  int  len  )
    {
        for  (  int  i  =  0;  i  <  len;  i++,  p++  )
        {
            Console.WriteLine(  *p  );
        }
    }

    [STAThread]
    static  unsafe  void  Main(string[]  args)
    {
        string  s  =  "unsafe  code";
        fixed  (  char*  p  =  &(  s.ToCharArray()[  0  ]  )  )
        {
            print  (  p,  s.Length  );
        }
    }
}
    
   
  
   



Output

u
n
s
a
f
e

c
o
d
e


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Unsafe
» Pointer