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 trialIlya Sikharulidze
Courses Plus Student 1,073 PointsI'm stuck!
I think I didn't understand really well what is a computed property and because of that I have no idea what to do here, can someone please help me!
namespace Treehouse.CodeChallenges
{
class Square : Polygon
{
public double SideLength { get; private set; }
public Square(double sideLength) : base(4)
{
SideLength = sideLength;
}
}
}
namespace Treehouse.CodeChallenges
{
public class Polygon
{
public int NumSides { get; private set; }
public Polygon(int numSides)
{
NumSides = numSides;
}
}
}
2 Answers
Steven Parker
231,269 PointsA computed property is just one that returns a value from a calculation using other fields instead of a value that was previously set. Computed properties often have only a "get" method and no "set".
Ilya Sikharulidze
Courses Plus Student 1,073 PointsI have been able to complete the challenge! Thanks for the help!
Steven Parker
231,269 PointsIlya Sikharulidze — Good job! You can mark a question solved by choosing a "best answer".
And happy coding!
Ilya Sikharulidze
Courses Plus Student 1,073 PointsIlya Sikharulidze
Courses Plus Student 1,073 PointsThank you, but I still don't really understand what I have to do here
Steven Parker
231,269 PointsSteven Parker
231,269 PointsWell, you have "SideLength" as an example of an auto property. For a computed property, the syntax will be similar but the "get" will have a body with code in it and the "set" can be omitted.
For the Area, the body code of the "get" can use "SideLength" to calculate the area and return it.
Give it a shot, and if you still have trouble, show the code you have for it so far.