Chapter 12

Interacting with Structures


check Determining when to use structures

check Defining structures

check Working with structures

Structures are an important addition to C# because they provide a means for defining complex data entities, akin to records from a database. Because of the way you use structures to develop applications, a distinct overlap exists between structures and classes. This overlap causes problems for many developers because it can become difficult to determine when to use a structure versus a class. Consequently, the first order of business in this chapter is to discuss the differences between the two and offer some best practices.

Creating structures requires use of the struct keyword. A structure can contain many of the same elements found in classes: constructors, constants, fields, methods, properties, indexers, operators, events, and even nested types. This chapter helps you understand the nuances of creating structures with these elements so that you can fully access all the flexibility that structures have to offer.

remember Even though structures do have a ...

Get C# 7.0 All-in-One For Dummies now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.