Explain the difference between Managed and Unmanaged code in .NET?
Explain the difference between Managed and Unmanaged code in .NET?
In .NET, the distinction between managed and unmanaged code is fundamental and revolves around how the code is executed and managed by the runtime environment.
Managed code is executed by the Common Language Runtime (CLR), which is a core component of the .NET framework. When you write code in high-level languages such as C#, VB.NET, or F#, it is compiled into an Intermediate Language (IL), also known as Common Intermediate Language (CIL) or Microsoft Intermediate Language (MSIL). This IL code is then executed by the CLR, which provides several essential services:
Unmanaged code, on the other hand, is executed directly by the operating system. This type of code is typically written in languages like C or C++ and is compiled directly into native machine code. Key characteristics of unmanaged code include:
Feature | Managed Code | Unmanaged Code |
---|---|---|
Execution | By CLR | Directly by the OS |
Memory Management | Automatic (Garbage Collection) | Manual |
Security | Built-in by CLR | Developer's responsibility |
Compilation | Compile... |
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào