Chapter 11

Interacting with Structures

IN THIS CHAPTER

Bullet Determining when to use structures

Bullet Defining structures

Bullet Working with structures

Bullet Working with records

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 determining when to use a structure versus a class can be difficult. 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 you to use 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.

Even though structures ...

Get C# 10.0 All-in-One For Dummies 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.