Default State for Structure Members

You want to know how to handle the default state of members in structures.

Create structures so that they’re in a valid state when their members are null or zero.

Defining parameterless constructors in structures is not permitted. It’s also illegal to define initial values for fields in structures. What happens is the CLR zeros out all fields when it creates the structure. As an example, consider a structure with a Boolean field or property. You’ll want to ensure that a false state is a valid initial value for it. Otherwise, you’ll want to rename the field to reverse its meaning.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s