class Program { private const string HelloWorld = "Hello World"; static void Main(string[] args) { Console.WriteLine(HelloWorld); Program.ChangeString(HelloWorld, "badflyer"); Console.WriteLine(HelloWorld); const string HelloWorld2 = "Hello World 2"; Console.WriteLine(HelloWorld2); Program.ChangeString(HelloWorld2, "not hello"); Console.WriteLine(HelloWorld2); Console.ReadLine(); } private static void ChangeString(string target, string newValue) { if(newValue.Length > target.Length) { throw new ArgumentException("The new string cannot be longer than the current string"); } unsafe { fixed (char* str = target) { // Change the length to match our new string. The length is stored as an int right in front of the first character *((int*)str - 1) = newValue.Length; // Copy the new string for(var i = 0; i < newValue.Length; i++) { str[i] = newValue[i]; } } } } }