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#

Single letter variables

You are discouraging single-letter variables, although - when inserting a for cycle for example - C# / Visual Studio itself uses it by default ("i" in this particular case).

1 Answer

Are you referring to a variable in a for loop?

// Loop
for(int i, i < 10, i++ )
{
    // sample code
}

// descriptive variable
float TotalPrice = 75.00;

If so, then using a single letter for the index example(i) is preferable. In most other cases, you will want to use descriptive variables so that you and other coders know what you are referring to 6 months later.

Yes, I was referring to for loops mainly, but any other loops where the variable is just kept as an index. Anyways, it could be put into the material as a strong exception - exceptions make the rule stronger, right? Also, if I want other coders to know what I did 6 months later, I'd use comments mainly. :)