Mega Code Archive

 
Categories / C# Tutorial / Unsafe
 

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 );     }   } } u n s a f e c o d e