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 trialjamesroyle
2,621 PointsUpper case and lower case X Y x y
Why do we use both upper case X and lower case X. We also do the same with Y but i don't understand why. Do they refer to different variables?
class Point {
public readonly int X;
public readonly int Y;
public Point(int x, int y)
{
X = x;
Y = y;
}
}
2 Answers
Steven Parker
231,268 PointsSince C# is a case sensitive language, names in upper case do indeed refer to different variables than names in lower case.
A convention used in this course (and often by developers) is to begin class variable names with upper-case characters, and name the parameters of the constructor that initialize them with a version that starts with lower case.
Peter McClory
2,365 PointsThe benefit of using this convention is to be able to look back at your code, in particular when working with other developers, and for it to be easier and quicker to see when a variable is a class variable or not. It's just a common convention that helps people to understand code that they have not written themselves, or code that you haven't looked at for a while.
jamesroyle
2,621 Pointsjamesroyle
2,621 PointsOk thanks. That has cleared that up. However, i'm still unsure what the benefit of this practice is.
Steven Parker
231,268 PointsSteven Parker
231,268 PointsAt the least, it's an opportunity to build some code using these conventions.