Using the unsafe keyword : Unsafe Code : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Unsafe Code »

 

Using the unsafe keyword








    


using System;

class Test {
  public static unsafe String UnsafeCodeExample( String s ) {
    int strLength = s.Length;
    char[] str = new char[strLength+1];
    string strReturn = "";

    fixed(char* strPointer = str) {
      for ( int i=0; i<strLength; ++i )
        strReturn += strPointer[i];
    }
    return strReturn;
  }

  public static void Main() {
   String s = UnsafeCodeExample("This is a test");
   Console.WriteLine( "Reversed: {0}", s );
  }
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Unsafe Code