What is the difference between managed code and unmanaged code in .NET?

1 Answers
Answered by suresh

What is the difference between managed code and unmanaged code in .NET?

In .NET, the main difference between managed code and unmanaged code lies in how they are executed by the Common Language Runtime (CLR). Managed code is code that is written in a language that is supported by the CLR, such as C# or VB.NET. It is compiled into Intermediate Language (IL) and executed by the CLR, which provides features like automatic memory management and exception handling.

Unmanaged code, on the other hand, is code that is not managed by the CLR. It is typically written in languages like C or C++ and directly interacts with the system resources. Unmanaged code is not subject to the same level of runtime checks and optimizations that managed code enjoys, making it potentially less secure and harder to maintain.

Overall, the key distinction is that managed code runs within the managed environment of the CLR, while unmanaged code operates directly with system resources. Understanding this difference is crucial for developers working with .NET to ensure optimal performance and security in their applications.

Answer for Question: What is the difference between managed code and unmanaged code in .NET?