C# C# Objects Inheritance Inheritance

Amanda Stewart
Amanda Stewart
1,371 Points

Having an issue with compiler errors in C# Objects course

Right now, when I submit it as listed in this post, it says that the "public" on line 16 was not expected. When I remove the "public" it asks if i am remembering to initialize sideLength with the constructor in the square class.

I'm stumped because I've basically copied and pasted the stuff they had us code in the previous video, then changed the values to what they should be per the question.

Can anyone tell me what I'm doing wrong?

Polygon.cs
namespace Treehouse.CodeChallenges
{
    class Polygon
    {
        public readonly int NumSides;

        public Polygon(int numSides)
        {
            NumSides = numSides;

        }

    }
    class Square : Polygon
        {
            public Square(int sideLength) : base(4)
            {
                public readonly int SideLength;
            }
        }
}

2 Answers

Steven Parker
Steven Parker
177,563 Points

You're close, but take a look at the "NumSides" field in "Polygon". Notice that it is declared at the class level instead of inside the constructor. You'll want your declaration of "SideLength" to be done similarly.

Amanda Stewart
Amanda Stewart
1,371 Points

Thanks! This was exactly what I needed!