Data Types in C# with Examples: Value and Reference Data Type
Learn about value and reference data types in C# with clear examples, and understand how each behaves differently in memory.
What is a Data Type?
A data type defines the kind of value a variable can hold and the operations that can be performed on it. C# is a strongly typed language, meaning every variable must have a defined type at compile time.
Value Data Types
Value types, such as int, float, bool, char, and struct, store their actual data directly in the variable itself. When assigned to another variable, the value is copied, so changes to one don't affect the other.
Reference Data Types
Reference types, such as class, string, array, and delegate, store a reference to the memory location where the actual data lives. Assigning one reference variable to another means both point to the same underlying object.
Key Differences in Behavior
Because value types are copied and reference types are shared, understanding this distinction is critical when passing data to methods or working with collections, as it directly affects how changes propagate through your program.
.png)