Skip to content

Instance Pattern - Enforce Instance Fields Similar to Interfaces #9204

Discussion options

You must be logged in to vote

Correct, fields are not considered part of the contract of a type. Per the .NET guidelines:

https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/field

❌ DO NOT provide instance fields that are public or protected.

It's better to expose them as properties, which provides more flexibility and encapsulation.

Replies: 1 comment 13 replies

Comment options

You must be logged in to vote
13 replies
@davemcdowell
Comment options

@franchyd
Comment options

@davemcdowell
Comment options

@HaloFour
Comment options

Answer selected by davemcdowell
@davemcdowell
Comment options

@franchyd
Comment options

@davemcdowell
Comment options

@jaredpar
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants