Home > DeveloperSection > Blogs > Difference between managed code and Unmanaged code

Difference between managed code and Unmanaged code

.NET C# 
0 Comment(s)
 1118  View(s)
Rate this:

Difference between managed code and Unmanaged code

In this blog, I’m explaining about  managed code and unmanaged code in C#.

Managed Code:               

1.       Managed code is executed under the control of CLR (Common language Runtime).

2.       There is no explicit memory allocation and de-allocation.

3.       There is no explicit call to the garbage collector.

Managed code= .NET Programs

Unmanaged Code:

Code that is directly executed by the operating system is known as unmanaged code or unsafe code.

Unsafe code is code which does not execute under full control CLR. It can cause some problems therefore each use must be marked as unsafe.

Fixed: In an unsafe context, the fixed keyword can be used to temporarily fix a variable so that its address may be found.

Right click on your project >>properties>> go to the build tab>> check unsafe code checkbox


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace UnsafeCodeExample


    class Program


        unsafe static void Main(string[] args)


            string str="Sita";

            fixed (char* value = str)



                char* ptr = value;

                while (*ptr != '\0')















Don't want to miss updates? Please click the below button!

Follow MindStick