Mega Code Archive

 
Categories / C# Tutorial / Unsafe
 

Get a pointer to the start of a string and display the contents of string via pointer

using System;    class MainClass {    unsafe public static void Main() {      string str = "this is a test";        fixed(char* p = str) {        for(int i=0; p[i] != 0; i++)          Console.Write(p[i]);      }      Console.WriteLine();    }  } this is a test