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

Luis Santos
Luis Santos
3,566 Points

I am stuck on this part, thought I had the problem worked out but apparently I don't. Any help will be appreciated.

I understood the challenge perfectly and felt I could do it with no problem. However, I got stuck according to the code challenge engine. I've looked at C# documentation and other posts concerning this particular problem. I have yet to find an adequate solution as to why my method of doing this problem is not working.

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


        public Polygon(int numSides)
        {
            NumSides = numSides;

                      public class Square : Polygon
           {

                      public readonly int SideLength;

                   public Square(int sideLength) : base (4)

                {
                SideLength = sideLength;

               }

          }
           }

2 Answers

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,485 Points

It looks right but wont pass challenge. I used my code & it passes but dont have time to really look at why right now. Heres what worked for me:

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

Steven Parker
Steven Parker
221,070 Points

It looks like you placed your new class inside the constructor for "Polygon".

:point_right: Move your class definition below the class definition for "Polygon".

You may also need to remove the "public" before "class". It didn't seem right, but I found it necessary to pass the challenge. You may want to report this as a bug to Treehouse Support.