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 ...

Get Programming PERL in the .NET Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.