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 trialLiam Andersson
1,396 PointsConstructor X,Y
Jeremy wrote X = x; and Y = y; why didn't he define X and Y as an integer or double? X, Y and Z are always numbers right?
And what exactly is a constructor? Im a bit confused over the constructor bit ;/
2 Answers
Steven Parker
231,198 PointsSince C# is case-sensitive, then "X" (capital) and "x" (lower case) are two different variable names. Same with "Y" and "y". And he did define "X" and "Y" both as "int" types, a few lines above where the constructor starts.
"X", "Y", and "Z" are just variable names, nothing special and not required to be any specific type.
And a constructor is a special method that runs automatically when you create an instance of a class. It will typically establish initial states such as setting up variables as is being done here.
Gancho Iliev
10,264 PointsHe define both as "int" types in this line of code:
public Point(int x, int y)
Liam Andersson
1,396 PointsLiam Andersson
1,396 PointsHe did? Then I missed it.. Well Thanks
Gancho Iliev
10,264 PointsGancho Iliev
10,264 PointsYour comments are so helpful! Thanks a lot, man!