O'Reilly logo

A Programmer's Guide to C# 5.0, 4th Edition by Nick Wienholt, Eric Gunnerson

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

CHAPTER 8

image

Structs (Value Types)

Classes are used to implement most objects. Sometimes, however, it may be desirable to create an object that behaves like one of the built-in types (such as int, float, or bool)—one that is cheap and fast to allocate and doesn’t have the overhead of references. In that case, you can use a value type, which is done by declaring a struct in C#.

Structs act similarly to classes, but with a few added restrictions. They can’t inherit from any other type (though they implicitly inherit from object), and other classes can’t inherit from them.1

A Point Struct

In a graphics system, a value class can be used to encapsulate ...

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