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 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.