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 trialMichael North
2,561 PointsCould not compile
I have been working with this code for a while now, and no matter what i try it will not compile can I please get some help or explaining on what I did wrong.
namespace Treehouse.CodeChallenges
{
class Square : Polygon
{
public double SideLength
public double area
{
get
{
return SideLength * SideLength;
}
}
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;
}
}
}
3 Answers
andren
28,558 PointsYou (accidentally I presume) have removed the get and set declaration for the SideLength
property, when the task starts it looks like this:
public double SideLength { get; private set; }
And you are not meant to change that line at all.
In addition you have named the property area
instead of Area
.
If you restore the SideLength
line back to what it's supposed to be, and fix the typo in the Area
property name like this:
namespace Treehouse.CodeChallenges
{
class Square : Polygon
{
public double SideLength { get; private set; } // Fixed this line
public double Area // area changed to Area
{
get
{
return SideLength * SideLength;
}
}
public Square(double sideLength) : base(4)
{
SideLength = sideLength;
}
}
}
Then your code will work.
Michael North
2,561 PointsThank you for the answer, but in the video Jeremy gets rid of the auto property. Please explain.
andren
28,558 PointsIn the video he changes the Location
property from not having a computed getter, to having one. In this challenge you are not asked to change an existing property but to add a new one. The SideLength
property and the Area
property are entirely independent. You don't have to do anything to SideLength
in order to create the Area
property.
Michael North
2,561 Pointsokay thank you!