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 Return Values

jamesroyle
jamesroyle
2,621 Points

Upper 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
Steven Parker
231,275 Points

Since 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.

jamesroyle
jamesroyle
2,621 Points

Ok thanks. That has cleared that up. However, i'm still unsure what the benefit of this practice is.

Steven Parker
Steven Parker
231,275 Points

At the least, it's an opportunity to build some code using these conventions.

Peter McClory
Peter McClory
2,365 Points

The 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.