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 Expression Bodied Members

Robert Stewart
Robert Stewart
4,771 Points

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

Robert Stewart
Robert Stewart
4,771 Points

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:

Robert Stewart
Robert Stewart
4,771 Points

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.

Robert Stewart
Robert Stewart
4,771 Points

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.