C# Value Type and Reference Type
DevSniper
129 Views
Value Data Type
- Pre-defined Type :- byte, sbyte, int, uint, short, ushort , long, ulong, float, double, bool , decimal, DateTime
- User-defined Type :- struct, enum
- It directly store the variable value in memory.
- it will use Stack memory to store the values of the variables.
- if we pass value type variable from one method to another method the system will automatically create a seprate copy of that variable and pass that copy variable in other method.so that if we change variable value in other method that will not reflect to parent or caller method
Reference Data Types
- Pre-defined Type :- object , string
- User-defined Type :- class ,interface, delegate
- it will contain memory address of variable.
- it would not store the variable value directly in memory.
- it store memory address of the another memory location that holds the variable value data.
- if we pass reference type variable from one method to another method the system will not create a seprate copy of that variable. it will pass same memory location in other method so that if we change variable value in other method that will reflects to parent or caller method.