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 trialArturs Dubra
4,748 PointsHelp needed with computed properties C#
These computed properties confuses me.
My guess is that I need to create 1-2 private fields(I have no idea witch ones) Then get the information about Square area out of them.(Again no idea how code this properly)
I would appreciate any help.
namespace Treehouse.CodeChallenges
{
class Square : Polygon
{
public double SideLength { get; private set; }
public Square(double sideLength) : base(4)
{
SideLength = sideLength;
}
public double Area
{
get
{
return SideLength;
}
}
}
}
namespace Treehouse.CodeChallenges
{
public class Polygon
{
public int NumSides { get; private set; }
public Polygon(int numSides)
{
NumSides = numSides;
}
}
}
2 Answers
anil rahman
7,786 PointsNot done this part yet but managed to figure it out for you :)
namespace Treehouse.CodeChallenges
{
class Square : Polygon
{
public double SideLength { get; private set; }
public Square(double sideLength) : base(4)
{
SideLength = sideLength;
}
public double Area
{
get
{
return SideLength * SideLength; //you were so close
}
}
}
}
You missed out the area equation
Arturs Dubra
4,748 PointsThank you
Ole Vølund Skov Mortensen
27,842 PointsOle Vølund Skov Mortensen
27,842 Pointshad problems understanding it as well. now that i see it, i feel so stupid for not remembering that bit about SideLength * SideLength = Area; and this was basic school math for me and i didn't remember it!!! Man, i got to brush up on my math skills now