411 REFERENCE · Wikibooks
C Sharp Programming/Keywords/unsafe
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Keywords unsafe
__TOC__
The unsafe keyword may be used to modify a procedure or define a block of code which uses unsafe code. Code is unsafe if it uses the "address of" (&) or pointer operator (*).
In order for the compiler to compile code containing this keyword, you must use the unsafe option when using the Microsoft C-Sharp Compiler.
class MyClass {
public static void Main() {
int x = 2;
// example of unsafe to modify a code block
unsafe {
DoSomething(&x);
}
}
// example of unsafe to modify a procedure
unsafe static void DoSomething(int *msg) {
Console.WriteLine(*msg);
}
}