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

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,558 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,558 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.