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 trialAmanda Stewart
1,371 PointsHaving an issue with compiler errors in C# Objects course
Right now, when I submit it as listed in this post, it says that the "public" on line 16 was not expected. When I remove the "public" it asks if i am remembering to initialize sideLength with the constructor in the square class.
I'm stumped because I've basically copied and pasted the stuff they had us code in the previous video, then changed the values to what they should be per the question.
Can anyone tell me what I'm doing wrong?
namespace Treehouse.CodeChallenges
{
class Polygon
{
public readonly int NumSides;
public Polygon(int numSides)
{
NumSides = numSides;
}
}
class Square : Polygon
{
public Square(int sideLength) : base(4)
{
public readonly int SideLength;
}
}
}
2 Answers
Steven Parker
231,268 PointsYou're close, but take a look at the "NumSides" field in "Polygon". Notice that it is declared at the class level instead of inside the constructor. You'll want your declaration of "SideLength" to be done similarly.
Amanda Stewart
1,371 PointsThanks! This was exactly what I needed!