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 trialNicolas Bastos
4,209 PointsI 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
231,269 PointsC# 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;
}
Habib Miranda
7,320 PointsIn 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
8,145 PointsThis was a great explanation, thank you!
Eric Scott
1,754 PointsThank you very clear and to the point.
Ali Dahud
3,459 Pointsso 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
231,269 PointsRemember 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
1,562 PointsBut 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
231,269 PointsThe constructor sets the field value to the argument value, so they are not different there.
They have different values in the "DistanceTo" function.
Noel Mowatt, Jr.
780 PointsNoel Mowatt, Jr.
780 PointsGreat explanation!
nfs
35,526 Pointsnfs
35,526 PointsGreat explanation, Steven Parker. One more thing, since you said:
Are there case-insensitive languages too? If so, then can you provide an example?
Thank you.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsSome examples of case-insensitive languages are Visual Basic, HTML, SQL, Fortran and COBOL.
nfs
35,526 Pointsnfs
35,526 PointsThank you, Steven Parker.
Abubakar Gataev
2,226 PointsAbubakar Gataev
2,226 PointsWhat is the purpose of doing X-x ?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsThe expression "X - x" computes the horizontal distance.