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 Static vs Instance Methods

Nicolas Bastos
Nicolas Bastos
4,209 Points

I dont get the difference between X and x or Y and y.

Like I said in the title, I dont know what the difference is between X and x, Y and y, Width and width etc.. Can someone please explain to me?

Thankyou in advanced!

3 Answers

Steven Parker
Steven Parker
231,236 Points

:point_right: C# is a case sensitive language.

So a name with an upper-case letter in it is a completely different thing than one with a lower-case letter instead.

In this course, and other Treehouse courses, you will often see the same name used for a passed argument and also for an instance variable, but the argument will start with a lower-case letter and the instance variable with upper-case. This is just to show that they are related in the code. But the code would work just as well if you used a completely different name for one or the other.

For example, this code:

public int Junk;
public void Sample(int junk)
{
    Junk = junk;
}

... would do exactly the same thing if you wrote it like this instead:

public int Junk;
public void Sample(int anothername)
{
    Junk = anothername;
}

Great explanation!

Great explanation, Steven Parker. :clap::clap::clap: One more thing, since you said:

C# is a case-sensitive language.

Are there case-insensitive languages too? If so, then can you provide an example?

Thank you. :smile:

Steven Parker
Steven Parker
231,236 Points

Some examples of case-insensitive languages are Visual Basic, HTML, SQL, Fortran and COBOL.

Thank you, Steven Parker.

What is the purpose of doing X-x ?

Steven Parker
Steven Parker
231,236 Points

The expression "X - x" computes the horizontal distance.

Habib Miranda
Habib Miranda
7,320 Points

In relation to this particular program, The X is the readonly value that is related to the Point class. Whereas the x is the value that is declared in the DistanceTo method. In the Point construct we created, there are also x and y values that we create to initialize the X and Y values that are part of the class. This x and y values become the X and Y values when we create an instance of Point in Main. The x and y values in the DistanceTo method are different altogether. They are values that pertain to that method and can be used to compare to the X, Y values that were initialized by the Point construct.

Jonathan Cooper
Jonathan Cooper
8,145 Points

This was a great explanation, thank you!

Thank you very clear and to the point.

Ali Dahud
Ali Dahud
3,459 Points

so heres what I didn't get from this answer:

then whats the purpose of writing X-x? I get that it calculates the horizontal distance. But why did he write it that way ? why didn't he just went straight X-X? Steven Parker

Steven Parker
Steven Parker
231,236 Points

Remember that "X" (capital) is the stored value in the class, and "x" (lower case) is the argument, so they represent different things. If you wrote "X - X" it would just subtract the stored value from itself and the result would always be 0 (zero).

Faisal Naamani
Faisal Naamani
1,562 Points

But here :

public Point(int x, int y) { X = x; Y = y; }

you are assigning X = x so shouldn't they be the same value? I don't get how their value is different.

Steven Parker
Steven Parker
231,236 Points

The constructor sets the field value to the argument value, so they are not different there.

They have different values in the "DistanceTo" function.