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 Encapsulation with Properties Computed Properties

Idan Amar
Idan Amar
798 Points

Computed Properties

Its probably way off wrong, i just dont understand it.. Thank you.

Square.cs
namespace Treehouse.CodeChallenges
{
    class Square : Polygon
    {
        public double SideLength { get; private set; }

        public Square(double sideLength) : base(4)
        {
            SideLength = sideLength;
        }
        public Square Area
        {
            get {
               return SideLength*4;
            }
        } 
    }
}
Polygon.cs
namespace Treehouse.CodeChallenges
{
    public class Polygon
    {
        public int NumSides { get; private set; }

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

1 Answer

andren
andren
28,507 Points

It's actually not way off. There are only two issues, and only one of those are code related.

The first issue is this line:

public Square Area

In that line you declare a property called Area with a return type of Square. The issue is that it does not actually returns a Square, but a double. So you need to change the return type to reflect that.

The second issue is your math. The instructions tell you to return the area of the square. That is done by squaring the side length, not by multiplying the length by 4.

Squaring in case you don't know basically just means to multiply a number by itself. So SideLength * SideLength is what the Area property should return.

If you fix those two issues then your code will work.