An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
For a C# class, the properties’ data is stored as part of the object instance on the managed heap.
More precisely:
- A class is a reference type. A variable of that class (for example,
Employee emp;) holds a reference. That reference itself is typically stored on the stack when it’s a local variable, or in another object/field if it’s a member. - The
newoperator allocates the actualEmployeeobject on the managed heap. That object’s instance fields (which back the properties) live in that heap allocation. - Properties in C# are essentially methods (
get/setaccessors) plus, usually, a private backing field. The backing field that holdsEmployeeIdorEmployeeNameis part of the object’s memory layout on the heap.
So for an Employee class with properties EmployeeId and EmployeeName:
- The local variable
emp(the reference) is on the stack (or in another object if it’s a field). - The
Employeeinstance is on the managed heap. - The data for
EmployeeIdandEmployeeName(their backing fields) is stored inside thatEmployeeinstance on the managed heap.
Structs differ: a struct variable holds the value itself, so its fields (equivalent to property backing fields) are stored wherever the struct instance is stored (stack or inline in another object).
References: