O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

1.9. Value and Reference Types

Types in C# are categorized as either value or reference types. The behavior when copying or modifying objects of these types is very different.

An object of a value type stores its associated data directly within itself. Any changes to that data does not affect any other object. For example, the predefined arithmetic types, such as int and double, are value types. When we write

double pi = 3.14159;

the value 3.14159 is directly stored within pi.

When we initialize or assign one value type with another, the data contained in the one is copied to the second. The two objects remain independent.

For example, when we write

double shortPi = pi;

although both pi and shortPi now hold the same value, the values are ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required