Structs

Structs are value types. Structs, like classes, act as container objects for many kinds of member data. They can implement constructors, constants, fields, methods, properties, indexers, operators, and nested types. In short, structs can support all the features that classes support. The differences between structs and classes are very few. Classes are reference types and therefore only references to data are stored in them. However, structs, being value types, can store the actual data. Structs are created on the stack. Therefore, structs enhance performance when compared to classes. Classes are created on the heap and are hence slower that structs. Classes compensate for their lack of speed by being able to inherit from other classes. ...

Get Special Edition Using C# 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.