Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Objects Encapsulation with Properties Accessor Methods

Mark Ramos
Mark Ramos
19,209 Points

Should all fields be private going forward?

At around 0:30 he says it's generally a bad idea to make fields public. So going forward, should I try to code all classes with private fields with accessor methods only (even though at the end of this course we still have a number of public fields)?

1 Answer

Steven Parker
Steven Parker
231,275 Points

You'll get a better feel for this as you progress through the courses, but you're essentially correct. And the default access level is "private" if you don't specify otherwise.

But you'll soon learn about properties, which will generally be a better way to expose public values than with fields/methods ... keep plugging and you'll see.