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

i think i did everything correctly but it still tells me to define the square class as an inner class of the polygon

so i think i did everything as required but it still tells me to define square as an inner class of the polygon class which i think i did when i did the (class Square : Polygon) when creating the class so what exactly is missing ?

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

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

1 Answer

Hey AbduRahman Ezzeldin! You are so close!! The issue lies in where you are entering the parameter for the Polygon:

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

We don't want to set the num sides = to 4 here. We just want the parameter to be take an int called numSides.

We enter 4 when we call the base class so that we can pass it in as an argument to the parent constructor. So, rather than typing numSides as the argument, this is where we want to add 4.

Hope this helps! Great job so far :D

thing is even if i do as you say it then asks if i got square as an inner class of polygon which is just like ? it is ?