To set this compiler option in the Visual Studio development environment
Open the project's Properties page.
Click the Build property page.
Select the Allow Unsafe Code check box.
the following is a method declared with the unsafe
modifier:
C#
unsafe static void FastCopy(byte[] src, byte[] dst, int count)
{
// Unsafe context: can use pointers here.
}
The scope of the unsafe context extends from the parameter list to the end of the method, so pointers can also be used in the parameter list:
C#
unsafe static void FastCopy ( byte* ps, byte* pd, int count ) {...}
You can also use an unsafe block to enable the use of an unsafe code inside this block. For example:
C#
unsafe
{
// Unsafe context: can use pointers here.
}
To compile unsafe code, you must specify the -unsafe
compiler option. Unsafe code is not verifiable by the common language runtime.
沒有留言:
張貼留言