Using the unsafe keyword : Unsafe Code « Language Basics « C# / C Sharp
- C# / C Sharp
- 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 );
}
}
Related examples in the same category