Mega Code Archive

 
Categories / C# Tutorial / Unsafe
 

Modifying an Immutable String with Pointer

class MainClass {   static void Main()   {     string text = "S5280ft";     System.Console.Write("{0} = ", text);     unsafe{     fixed (char* pText = text)       {           char* p = pText;           *++p = 'm';           *++p = 'i';           *++p = 'l';           *++p = 'e';           *++p = 'A';           *++p = 'B';       }     }     System.Console.WriteLine(text);        } }