C# Unsafe code

Pointer store the address of a variable. The value of that variable can be accessed by directly referring to the memory location as stored in the pointer. One can achieve the capabilities of pointer by using unsafe code in C#.

C# the function of pointers are achieved using the keyword unsafe in the class declaration. The unsafe code is compiled with the unsafe switch of the compiler. Even through the unsafe code helps in accessing the memory, the unsafe code work will under the CLR.



To run unsafe code in visual studio setting: Right click on solution >> property >> Build tab >> Check Allow unsafe code