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

"Did you convert the property to a single-lined, expression bodied property?" error.

I'm not sure how to solve challenge task one for the code challenge. I keep getting the above error when I submit this code.

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

    public double Area { get; set; }

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

    public void Scale(double factor)
    {
        SideLength *= factor;
    }
}

}

I'm not sure why this is wrong. Help?

1 Answer

Steven Parker
Steven Parker
231,271 Points

:point_right: You should not change the value returned by the computed property.

You just need to change the form of the definition.

To see an example of this kind of refactoring, skip to about 01:30 in the video Expression Bodied Members.

John Paige
John Paige
7,436 Points

Hey Steven Parker. I am curious about why the passing code needs to use the "=>" sign as opposed to the "=". Initially i just used the "=" sign and it didn't pass. Then I edited the sign, and it passed. It seemed like the "=" would be correct in this context, considering that the area of any square can't possibly be greater than the square of one of its sides.

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

        public double Area => SideLength * SideLength; //<---When the sign is "=", it does not pass.


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

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



    }
}