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

Lucas Moraes de Souza
Lucas Moraes de Souza
1,634 Points

Did you define your Square class as an inner class of the Polygon class? Please help me

It says "Did you define your Square class as an inner class of the Polygon class? Be sure to define the Square class before or after the definition for the Polygon class". And this comes up all the time, I don't know what I am doing wrong, I'm still new to this.

Thank you!

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

        public Polygon(int numSides)
        {
            NumSides = numSides;
            NumSides = 4;
        }
    }

}

class Square : Polygon
    {
        public readonly int SideLength;

        public Square(int numSides) : base(4);
        {
            SideLength = sideLength;
        }
    }

1 Answer

Steven Parker
Steven Parker
231,271 Points

Both classes should be in the same namespace.

I'm not sure what they mean by "inner class", but the Square class should be a peer of the Polygon class. You just need to move it inside the namespace with Polygon.

Also, the name of the parameter declared in your constructor doesn't match the name used in the assignment in the constructor body.