What is unmanaged code in C#?

CsharpProgrammingServer Side Programming

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 −


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);
Published on 21-Aug-2018 17:00:49