Chapter 12
Interacting with Structures
IN THIS CHAPTER
Determining when to use structures
Defining structures
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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access
Even though structures do have a ...