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 trialCarlos Pizarro
Courses Plus Student 1,878 PointsC# Objects 3 - Using the keyword base (I simply do not get it)
The exercise is asking me to set the value the value of sumSides using the base. I have tried all kind of ways but it is not working.
namespace Treehouse.CodeChallenges
{
class Polygon
{
public readonly int NumSides;
public Polygon(int numSides)
{
NumSides = numSides;
}
}
class Square : Polygon
{
public readonly SideLength;
public Square(int numSides) : base(numSides)
{
}
}
}
4 Answers
Steven Parker
231,198 PointsThe error messages give you hints. This code gets a response of "Bummer: Did you create a public readonly integer field named SideLength in the Square class?" And while the field is declared "readonly", it's missing a type.
Once you fix that, you'll see "Bummer: Does your Square constructor take a single parameter named sideLength?" The constructor parameter shown here is named "numSides" instead.
And finally "Bummer: Did you initialize the field 'numSides' to 4 in the base constructor?" And the parameter given to "base" to initialize numSides with in this code is "numSides" itself instead of 4.
Tobias Johansson
Courses Plus Student 722 PointsWhy why why can't i find a solution here, WHY WHY WHY do you refuse to simple give out the solution, so if someone is stuck you rather have them waste time not knowing what to do. I understand that people should be encourage to try and work it out themselves, but sometimes you get stuck. And the idea that i should post here and have to wait, hoping that someone will post an answer, OH NO SORRY YOU DON'T DO THAT, i still don't know what to do,i tried to initialize numSides to 4 but nope, Maybe i am just that stupid. Maybe , but one thing is for sure, I'm thankful that i am not paying because treehouse thinks its a good why to respect its users time by posting problem without solutions, HINT, ITS NOT. I spent 1 hour, maybe 2 hours on this , that is 2 hours that i didn't learn anything. Nothing, and you know i sort of think that's how you want it, you look at that wasted time to be equal to more time and untimely money spent here. SO THERE YOU GO. MAYBE I AM JUST TO STUPID AND MISSING SOMETHING OBV BUT I AM NOT TO STUPID TO KNOW THAT THIS SITE IS NOT GETTING ONE CENT FROM ME. I was happy before this, i was gonna sub, but now hell no. If anyone is thinking about paying, take a look at Lynda.com or plursight , or any of million youtube vidoes out there that teach programming for free, and above all don't waste peoples time. Bye.
Steven Parker
231,198 PointsThe answer I gave to Carlos was apparently exactly what he needed to reach a solution, so I'm not quite sure how your comment applies here. Also, for the most part, we are all just students helping each other here — none of us get any of your money.
Tobias Johansson
Courses Plus Student 722 PointsYou can't figure out how my comments applies here. You want me too explain it, or do you want me to give you hints, so that you yourself can figure it out on your own ? What do you think is the most reasonable, and less infuriating option of the two ? In the meantime, i still havn't figure out how too initialize the field 'numSides' to 4 in the base constructor...
Steven Parker
231,198 PointsPerhaps I was being overly diplomatic. It's actually quite clear why your comment doesn't apply at all to a question someone else asked, and who was entirely satisfied with a non-spoiler answer.
But I'm not without sympathy for your frustration. If you use the "breadcrumbs" at the top of a question, you can look at other questions about the same issue, and you can often find others where the solution code shown will serve as an example for your own issue, such as this one.
Tobias Johansson
Courses Plus Student 722 PointsI had the exact same problem, only unlike Carlos i wasn't able to figure it, so you saying my comments doesn't apply is just wrong. Also , the other question you know link to, i didn't find it, maybe if Treehouse was more user friendly, but its not.
Steven Parker
231,198 PointsMy point was that Carlos had not asked for a more explicit answer, and he was successful and satisfied with the answer I provided on the same day. He clearly wasted no time and responded with "I see it!! Thank you so much!" just 10 minutes later. What you've posted today (2 weeks later) is about something entirely different. I'm willing to forgive the inflammatory tone out of sympathy for frustration but it was clearly not related to the question or the answer already given.
The first link I posted above should take you to an index of other questions all about the same topic. And the last one, which I will repeat here (click that word), is for a specific other question from that index that I believe will satisfy you.
Carlos Pizarro
Courses Plus Student 1,878 PointsCarlos Pizarro
Courses Plus Student 1,878 PointsI see it!! Thank you so much! I could not even slep well because of this. I felt bad when i saw such little mistake.
Emil Hejlesen
3,014 PointsEmil Hejlesen
3,014 PointsThank you that was very helpful :) really good way to explain the problem 10/10
Steven Parker
231,198 PointsSteven Parker
231,198 PointsA little extra positive feedback is nice to get on this one! Glad it's still helping folks.