Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Methods Methods

Jesse Wolf
Jesse Wolf
944 Points

Why are you specifying Point point twice and why is 1 capital letters and one lower case letters?

Why are you specifying Point point twice and why is 1 capital letters and one lower case letters?

I don't fully grasp the reason for this.

1 Answer

andren
andren
28,521 Points

When you create a method that takes a parameter you have to first define the type of the parameter and then the name. Point is the parameter type and point is the parameter name. The name could have been anything, it doesn't have to be point. But the type has to be Point because that is based on the class name.

You are telling C# that you are expecting to be passed a Point object and that it should be assigned to a variable called point. It is the same as if you set up a method that was expecting a string or an int. Except that instead of using built-in datatypes you are using a class you created yourself, which is also considered a type of data in C#.

While it can be confusing for beginners it is pretty common to name variables that will hold an instance of a class the same as the class itself (just in lower camelCase), though as I mentioned above that is not mandatory. You can use whatever name you find appropriate.

You stated Java instead of C#, but the same is true for both languages I believe. I'm going to definitely upvote this answer.

andren
andren
28,521 Points

Oops you are right, I often answer Java questions on this forum so that was a typo on my part. Thank you for pointing that out to me, I have now corrected the post.

And it is indeed the same in both languages. Java and C# are quite similar at least as far as the basics of the languages are concerned.