What is unsafe/unmanaged code in C#?

Applications that are not under the control of the CLR are unmanaged. The unsafe code or the unmanaged code is a code block that uses a pointer variable and allows pointer usage in unmanaged code.

The following is the code −

static unsafe void Main(string[] args) {
   int x = 100;
   int* a = &x;

   Console.WriteLine("Data : {0} ", x);
   Console.WriteLine("Address : {0}", (int)a);

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started