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!
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 trial
I feel like the public bool OnMap(Point point) part was not explained properly
The fact that whilst creating this bool method, it creates a new instance of the Point class was not really explained. I still cannot get my head around it. Also, the task after this is different as it takes an integer, where here it is of type Point.
Can someone please explain. Thanks
Steven Parker224,849 Points
The OnMap method described in the video does not create a new instance of the Point class. But it requires that a Point object be passed as a parameter.
The type and quantity of arguments passed to a method will vary depending on the purpose of the method. The techniques you are learning should apply to different situations, and you will be exposed to a variety in the course videos and challenges.
Scott George19,060 Points
See if I've got this The upper case (Point...) is referencing the Point class and the lower case (point...) is telling the Point class what is wants it to do, which is "bool onBounds = point.X >= 0 && point.X < WIdth && point.Y >= point.Y < Height; return inBounds;"
If my explanation make sense.
Daniel W1,341 Points
The easiest way to not get confused is to think of Point as being there instead of any other type declaration like "string" or "int". The "whatever" is of the type Point, but it can also be called point. By convention as explained in the videos, you use all lower case letters for method parameters. This "whatever" of yours is a reference to whatever was passed into the function from anywhere else in the code, and lives within the function. Where as if it has a capital letter, you know it's either a class or that an instance variable.
Md shujaul Haque839 Points
why we use x,y variable .... like point.x and pint.y ........ x and y are not initialize in the field . ??
Yes I think I got confused because the word point is heavily used.
I just realised that that bool Method could even be written like:
because we created the Point class, and the Point constructor. Therefore it necessarily means when we create a new point object elsewhere, it has the properties of X and Y.
So even naming the argument for the bool method as 'whatever' still works