26.2. Differences between a struct and a class
Despite their apparent similarity, there are several differences between a struct and a class – and you cannot use structs as if they are identical to classes. Five major differences are discussed below.
26.2.1. Value type versus reference type
The most important distinction is that a class is a reference type, while a struct is a value type. [6]
[6] A brief recap of reference and value types follows for convenience. See Chapter 9 for a fuller explanation.
A reference type variable stores the address of an object. It is possible to have multiple reference type variables referring (or pointing) to the same object in memory, so that any operations on one of the variables will affect the same shared ...
Get From Java to C#: A Developer's Guide 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.