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

what's the correct answer?

I can't figure out what the correct answer is.

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

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

        public Polygon(int numSides)
        {
            NumSides = numSides;
        }
    }
}
Steven Parker
Steven Parker
218,654 Points

It doesn't look like you've written any code yet.

At least please give it a good-faith attempt and then ask for help if you have trouble.

And as a hint: the area of a square is side length multiplied by itself.

I've been working in this for a few days now and I've tried out a bunch of things that didn't work. I followed the error messages that are displayed on preview and this one had the least errors (only 1).

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

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

    }
    public double Area 
    {
        get 
        {
            return SideLength *= SideLength;
        }
    }
}

3 Answers

Patricia Hector
Patricia Hector
42,901 Points

Check it from inside to outside -your SideLength property is closed, you have two curly brackets { ...} -your constructor (Square) is closed as well, two curly brackets {...} -your Area property and class Square have two -but your namespace has one open curly bracket but there is not a close curly bracket

You can also use a trick: count how many open curly brackets and close curly brackets you have. If the result is the same, everything is fine if it's not, then check your work again. In this case, just add one to the end of the document.

Fantastic you were right! Thatnk s lot!

Steven Parker
Steven Parker
218,654 Points

You're really close there.
There was originally a closing brace on line 10, but it seems to have gone missing. Be sure to put it back.

But you also don't want to use a multiplication assignment operator ("*=") in your computed property. This permanently changes the value of SideLength. All you need is an ordinary multiplication operator ("*").

The challenge might let you get away with it, but it shouldn't. That's actually a bug in the challenge and you might want to report it to Support.

Patricia Hector
Patricia Hector
42,901 Points

Everything is fine Barry, you are just missing a curly bracket after your property.)

besides the one that is under it?