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

Andras Andras
Andras Andras
8,230 Points

C# Class Method - Properties

Hello there,

I need some help for the following code that;

public bool OnMap (Point point)
        {
        bool inBounds = 
            point.X >= 0 && point.X < Width 
            point.Y >= 0 && point.Y < Height;

        return inBounds;
        }

So, we created a Point point property inside OnMap method. Point is the custom type that refers to Point.cs (or Point Class) the point with lower case is its name. Inside the method we used point.X and it's simply refers to the X,Y variables from the Point Class, however X is also the name of the variable and it seems there are two names next to each other. Why do not we use Point.X and Point.Y with uppercase letters?

1 Answer

Steven Parker
Steven Parker
231,198 Points

:point_right: The argument's name is "point" (with lower-case "p")

So if you want to refer to a property inside it, you preface the property with the name, like "point.X".

A capital "P" would refer to the class itself, and would only be used to prefix static variables of the class. Since these properties are instance elements, they can only be accessed through a class instance such as the function argument.