O'Reilly logo

C# Primer Plus by Klaus Michelsen

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

Value Types and Reference Types

Structs are value types, so when a struct object is assigned to a variable, the whole value is assigned, as opposed to reference-based values where only the reference is passed along. This can often lead to significantly different behavior between reference and value types.

Note

It is generally more efficient to pass class instances around in a program than struct-based values because the former only involves a simple reference whereas the latter involves the whole value.

Consider, for example, the method called UpdateTime defined in lines 37–42 of Listing 18.4. It has one formal parameter of type TimeSpan. When we ...

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