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 Encapsulation with Properties Expression Bodied Members

WTF

What is the procedure here when the program won't take the correct answer?
public class Polygon { public int NumSides { get; private set; }

        public Polygon(int numSides)
        {
            NumSides = numSides;
        }
    }
    class Square : Polygon
    {
        public double SideLength { get; private set; }
        public double Area { get => SideLength * SideLength; }

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


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

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

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

        public void Scale(double factor)
        {
            SideLength *= factor;
        }
    }
}
Polygon.cs
namespace Treehouse.CodeChallenges
{
    class Polygon
    {
        public int NumSides { get; private set; }

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

4 Answers

The program is not taking the correct answer for this exercise: public double Area { get => SideLength * SideLength; } What is the procedure here ?

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Robert Stewart! You're very close! I'd encourage you to visit the preceding video and watch around the 1:54 mark. You have an extraneous get and some extra curly braces. Here is the C# documentation for expression body members for properties.

public double Area => SideLength * SideLength; 

Hope this helps! :sparkles:

Jennifer, thx very much !

Yeah Thank you for the answer Jennifer Nordell, however it still bothers me that it took me 2 hours of rewatching the video and some previous ones to get to the answer. The instructions are not clear enough to guide one to the syntax that one is supposed to write and neither are the suggestions that the page makes when you have tried a wrong attempt, some of these suggestions talka about declaring the property inside Square and then it simply doesnt help much more in how one is supposed to calculate the square, since we cant use anything else like a Math.Pow function etc...

This whole C# course beginner course has just been a horrible experience, very little guidance, unclear project that you chose for us to work on, and stupidly organized order of things to learn. You are teaching us about error messages before having gone through various functions, training us how to write proper property and method syntax etc.

Sorry but after spending days on this one little course (and having ZOOMED through the Javascript one in less then a day and remembering almost everything) I had to voice my concerns, hope you take them to heart and don't just ignore this.

This is all fixed. I was just not used to the way the editor works with the course. I have it down now sorry about the terse comment I was just worried at the time that I was stuck in the course. Using the Team TreehouseCommunity supplies you with plenty of feedback for any troubles that you might have.