C # allows pointer variables to be used in a function when a block of code uses the unsafe modifier tag.
Unsafe or unmanaged code refers to a block of code that uses a pointer variable.
The following example illustrates the use of a Pointer when the unsafe modifier is used in C #:
Using System;namespace unsafecodeapplication{ class program { static unsafe void Main (string[] args) { int var =; int* p = &var; Console.WriteLine ("Data is: {0}", var); Console.WriteLine ("Address is: {0}", (int) p); Console.readkey ();}}}
In order to compile unsafe code, you must switch to the command-line compiler to specify the /unsafe command line.
For example, to compile a program named Prog1.cs that contains unsafe code, you would enter a command on the command line:
/ unsafe Prog1 . CS
If you are using the Visual Studio IDE, you need to enable unsafe code in the project properties.
The steps are as follows:
- Open Project Propertiesby double-clicking the Properties node in Resource Manager (Solution Explorer).
- Click the Build tab.
- Select the option "Allowunsafe code".
can refer to http://www.w3cschool.cc/csharp/csharp-unsafe-codes.html
C # unsafe code