What is unmanaged code in C#?



The following states what is an unmanaged code −

  • 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.
  • The unsafe modifier allows pointer usage in unmanaged code.

Here is the module showing how to declare and use a pointer variable. We have used the unsafe modifier here.

Let us see the example −

Example

static unsafe void Main(string[] args) {
   int var = 20;
   int* p = &var;

   Console.WriteLine("Data is: {0} ", var);
   Console.WriteLine("Address is: {0}", (int)p);
   Console.ReadKey();
}
Samual Sam
Samual Sam

Learning faster. Every day.


Advertisements