What are the 2 broad classifications of data types available in C#?
Short answer
C# data types fall into two broad classifications called value types and reference types.
Advertisement
AModel answer
C# data types fall into two broad classifications called value types and reference types. Value types, such as int, double, and bool, store their actual data directly in the memory location of the variable itself, usually on the stack, while reference types, such as classes, arrays, and strings, store a reference or pointer to the actual data, which lives on the heap, meaning the variable itself simply holds an address pointing to that data.
int number = 10; // value type, stores 10 directly
Customer customer = new Customer(); // reference type, stores an addressReal-world example
A developer debugging unexpected shared state realizes that two variables pointing to the same Customer object, a reference type, were both affected by a single change, while similar confusion never happens with simple value types like int.
Likely follow-ups
- What are examples of value types and reference types in C#?
- How does this classification affect how variables are passed to methods?
Related topics