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 Initialization

Richard Juliano
PLUS
Richard Juliano
Courses Plus Student 74 Points

little confused I changed the public to readonly and it still says did I delete the public modifier?

am I doing this wrong?

Frog.cs
namespace Treehouse.CodeChallenges
{
    class Frog
    {
        readonly int TongueLength;
    }
}

2 Answers

I think you're supposed to keep the field public so it looks like this:

namespace Treehouse.CodeChallenges
    {
        class Frog
        {
            public readonly int TongueLength;
        }
    }
Daniel W
Daniel W
1,341 Points

Public and private keywords just specify what classes can access the variable. If it's public it means other classes can access the variable. If it's private only the class it's in can access it. If you have no declaration, the default access for would be the most restricted access you could declare for that member.

So with this said, variables can still be "readonly", regardless of their access modifiers. It just means that the variables cannot be written over, and thus they are sort of like constants in a way.