C# Programming/Keywords/unsafe
Appearance
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);
}
}
C# Keywords | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Special C# Identifiers (Contextual Keywords) | |||||||||||||||
| |||||||||||||||
Contextual Keywords (Used in Queries) | |||||||||||||||
|