
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Managed code vs Unmanaged code in C#
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.
Let us see the example −
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); Console.ReadKey(); }
Managed Code
Managed code is a code whose execution is managed by Common Language Runtime. It gets the managed code and compiles it into machine code. After that, the code is executed.The runtime here i.e. CLR provides automatic memory management, type safety, etc.
Managed code is written in high-level languages run on top of .NET. This can be C#, F#, etc. A code compiled in any of this language with their compilers, a machine code is not generated. However, you will get the Intermediate Language code, compiled and executed by runtime
C/C++ code, called "unmanaged code” do not have that privilege. The program is in binary that is loaded by the operating system into the memory. Rest, the programmer has to take care of.
- Related Articles
- Difference between Managed and Unmanaged code in .NET
- What is unmanaged code in C#?
- What is unsafe/unmanaged code in C#?
- What is a managed code in C#?
- Difference between a Managed and an Unmanaged Switch
- How to Install Git in Vs Code?
- How to upload a project to GitHub from VS Code?
- 8085 code to convert binary number to ASCII code
- Differentiate between Fastag, Bar Code, QR Code and NFC.
- Code splitting in React.js
- Gray Code in C++
- Code Division Multiplexing
- Pulse Code Modulation
- Python Code Objects
- Morse Code Translator in Python
