views:

552

answers:

4

When writing my first asp.net MVC application using C#, I see that there are some variables whose name start with an underscore character(_).

What does this mean? Is there any specific meaning for this?

+5  A: 

In general, this means private member fields.

Ben Robbins
More generally, for non-public instance fields (that includes protected and internal ones too).
Noldorin
+1  A: 

A lot of people use them for property private variables (the variables that actually store the values for public properties).

Steven Robbins
+6  A: 

There's no language-defined meaning - it's just a convention some people use to distinguish instance variables from local variables. Other variations include m_foo (and s_foo or g_foo or static variables) or mFoo; alternatively some people like to prefix the local variables (and parameters) instead of the instance variables.

Personally I don't use prefixes like this, but it's a style choice. So long as everyone working on the same project is consistent, it's usually not much of an issue. I've seen some horribly inconsistent code though...

Jon Skeet
A: 

I have seen it used as a variable name for parameters which are not being used as a way to 'hide' them away from the rest of the function.

I can't say this is a good or bad thing but it was effective at indicating that the parameter was not to be used in the function.

ShuggyCoUk