C# Type System
In C# there is a fundamental distinction between value types and reference types. Value types have storage allocated immediately on the stack when the variable is declared. Reference types have storage allocated on the heap, and the variable is only a reference to the actual data, which can be allocated later.
We looked at classes in the first section. A class defines a reference type. In this section we survey the entire C# type system, including simple types such as int and decimal. In C# a struct has many similarities to a class but is a value type. Another important kind of value type in C# is an enum. All types in C# are rooted in a fundamental base class called object.[3] In C# “everything is an object,” and value types are ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access