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

The Polygon class represents a 2 dimensional shape. It has a public field named NumSides. Create a new type of polygon c

I can't figure what's wrong with this, any ideas?

Polygon.cs
namespace Treehouse.CodeChallenges
{
    public Polygon(int numSides)
    {
        NumSides = numSides;
    }
}

    class Square : Polygon
    {
        public readonly int SideLength;

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

2 Answers

Steven Parker
Steven Parker
230,995 Points

Right code, wrong place.

You just need to put your new class inside the namespace. Otherwise, good job! :+1:

Hi Steven, I moved the curly brace from just after the code block contained in numSides to the end of the code to include in the namespace but it's still incorrect, it says: "have you deleted the polygon class?"

Steven Parker
Steven Parker
230,995 Points

Sure enough, it looks like part of the original code got deleted. The code above is missing both the definition of the Polygon class and the declaration of the NumSides property. When I open the challenge fresh it has those code lines.

Be sure to add your new class without removing any of the original code.

Thanks Steven, fixed it now by reloading the question, not sure how i managed to delete it!