Classes and Other Types

So far, we’ve not made the distinction between a class and a type concrete. The CLR supports multiple sorts of types (not to say “types of types”), but one big top-level distinction can be made, as follows:

• Variables of a value type immediately contain the data. When assigned to another variable (for example, also when passing to a method parameter), the contents are copied by value. So value types are passed by value (by default).

• Variables of a reference type store a reference to the data. This means multiple variables can refer to the same object, a principle called aliasing. So reference types are passed by reference.

The definition of a reference type is called a class, whereas that of a value type is called a ...

Get C# 4.0 Unleashed 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.