...

/

Value vs. Reference Types

Value vs. Reference Types

Learn how objects are stored in memory.

We’ve learned about the primitive types and have also worked with classes and structs. It’s time to classify them all. All data types in .NET are divided into two categories: value types and reference types.

When we create a variable of a value type, a place in memory is allocated for that value and the slot contains the actual data.

Note: All primitive types like int, double, bool, float, and char are examples of value types. When we create a struct, we create a value type. Primitive types are essentially structs.

Value type variable

Consider the following example:

int age = 25;

The age variable is a slot of memory, and that slot contains the actual value which, in this case, is 25.

Another important feature of ...

Main's stack
Access this course and 1400+ top-rated courses and projects.