Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Encapsulation with Properties Accessor Methods

Mark Ramos
Mark Ramos
19,196 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
216,020 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.