What is the best practice for using public fields?

I only ever expose public fields when they’re (static) constants – and even then I’d usually use a property.

By “constant” I mean any readonly, immutable value, not just one which may be expressed as a “const” in C#.

Even readonly instance variables (like Result and Message) should be encapsulated in a property in my view.

See this article for more details.

Leave a Comment