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 Object-Oriented Programming Wrap-up

Darya Zata
Darya Zata
2,562 Points

Readonly fields can be set

I dont understand maybe the question but also the explanation :

Q: Readonly fields can be set..?

i chose: as often as needed, but only from inside the class

-> Bummer! Private fields that are NOT readonly can be set as often as needed from inside the class.

i tried to compile some examples, but i think i dont get neather the question fully nore the answer, can someone explain it pls thanku!

1 Answer

Steven Parker
Steven Parker
229,708 Points

Readonly fields can only be set by the constructor. After the constructor finishes, they cannot be set even from inside the class.

Darya Zata
Darya Zata
2,562 Points

Hello Steven,

ok thank you this i guess i understand, and why the answer says private! fields can be set as often as needed inside the class, what if they are public? I thought its even easier to set them

Steven Parker
Steven Parker
229,708 Points

Darya Zata — You are correct, pubic fields can be set from both inside and outside the class.

Glad I could help. Remember to choose a "best answer" to mark your question complete.
And happy coding!