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

michael Durkopp
michael Durkopp
1,228 Points

No matter what I do, I keep getting Did you convert the property to a single-lined, expression bodied property? error

I must be blind here, because no matter what I do, I can't seem to get pass the challenge. I Literally converted(?) all the Expressions into single-lined, expression bodied property based on the Expression Bodied Members video. but I still get the error.

Also I get a compiling error when I remove the '()' from public double Area() => SideLength * SideLength;

I can't seem to get a good answer on what I'm doing wrong here.

help?

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

        public double Area() => 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;
    }
}

2 Answers

Hi Michael

Your code is correct, however the treehouse compiler is failing because it did not ask you to change the polygon.cs as well as did not ask you to change the square method.

If you revert these back you will pass.

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

        public double Area => SideLength * SideLength;


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

        public void Scale(double factor) => SideLength *= factor;

    }
}
michael Durkopp
michael Durkopp
1,228 Points

Thank you Liam!

Well this is embarrassing! I re-read the instructions for the challenge, and now I see what I was supposed to do.

Thought I was supposed to convert all of Square.cs into a single line property.

I guess I was not at %100 when I was doing the challenge at the time.

Live and learn in this case.

By the way, would this:

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

Be valid normally? I didn't see an error in the preview, so I was just wondering.

From looking at it, I believe it is valid, I would have to test it to confirm it though.

One thing which may be helpful is checking out the different operators

Good Luck!