O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

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

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

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