Feature | Managed Code | Unmanaged Code |
---|---|---|
Memory Management | Handled by CLR (Garbage Collection) | Developer must manage manually |
Security | Built-in security checks | More vulnerable to memory leaks and attacks |
Execution | Runs within .NET environment | Runs directly on OS |
Language Examples | C#, VB.NET | C, C++, Assembly |
Managed Code Example (C#)
using System;
class Program {
static void Main() {
Console.WriteLine("Hello, Managed Code!");
}
}
Unmanaged Code Example (C++)
#include <iostream>
using namespace std;
int main() {
cout << "Hello, Unmanaged Code!";
return 0;
}
Interop Between Managed and Unmanaged Code
DllImport
to call a Windows API function from C#.