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 trial

C# C# Objects Methods Methods

Graham Atlee
Graham Atlee
3,907 Points

Can someone help break down bool OnMap(Point point) method?

I've been struggling with this concept. I'm not fully sure what's going on here.

Like why does point.X allow us to access that field from the Point class. I get that its a variable but how can a variable access another variable?

Overall I'm just confused with this whole method in general. I just need a better explanation.

2 Answers

Daniel Quaidoo
Daniel Quaidoo
23,937 Points

He has a good point. The use of point.X was not properly explained in the video.

The first thing to realise is that (Point point) is a class that you are referring to. But you are kind of using it as a type.

Then to the Point.X itself, it has to do with the dot operator. The documentation will probably explain this better than i can.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operator

Steven Parker
Steven Parker
231,236 Points

An object is more than a variable. You might think of it as a box that can hold other things, including variables and functions. A method is essentially a function that is inside an object.

And the "X" part of "point.X" is simply a variable named "X" that is inside an object named "point".

Did that cover what you were asking? I wasn't sure I understood the question. If not, perhaps showing a bit more of the code would help.