🌌 Data types refer to a type of data for example character, sequence of characters (string), whole number , decimal etc 🌌 C# is a strongly typed language which means you have to indicate the data type of a value that a variable will refer to 🌌The Datatypes are something which gives information about: 1. Size of the memory location. 2. The range of data that can be stored inside that memory location 3. Possible operations which can be performed on that data type.
Data types in C#:
The 3 fundamental data types in C# based on memory allocation are:
- Value Data Types – Value type data types are those that hold a data value within its own designated personal memory space. Static memory allocation (stack).
- Structs: Stands for structure, Some structs are: long, int, float, double, decimal, char, bool etc Each has memory allocated to it for example int —> 32 bits
- Enums: An enumeration is a set of named integer constants
- Reference Data Types – These data types contain a reference to the variables in the stack and store the value in the heap.
- Pointer Data Types – A pointer is a variable whose value is the address of another variable i.e., the address of the memory location.
Stack and Heap
The stack is the main/major memory area in your program which is responsible for memory allocation in your program.
Whenever you declare a value type variable its going to allocate some static memory area called stack
For reference types , memory is allocated in the stack for the reference but the value of the variable is stored in the heap which is dynamically created at runtime. So its in action whenever required