3
Answers

Why we use underscore before variable name in C# ?

Himanshu Pandya

Himanshu Pandya

10y
2.6k
1
It's usually to see a _var variable name in a class field. What does the underscore mean? 
 
   Thanks 
Answers (3)
3
Mahesh Chand

Mahesh Chand

1 286.4k 123.7m 10y
It means nothing. You don't have to use it. It used to be a naming standard but not anymore.
1
Vulpes

Vulpes

NA 98.3k 1.5m 10y
A lot of C# programmers like to precede field names with an underscore and a lower case letter to distinguish them from an associated property which begins with an upper case letter. For example:

private string _name;

public string Name
{
    get { return _name;}
    set { _name = value; }
}

This is just a convention and you don't have to follow it if you're allergic to underscores.

One thing you shouldn't do is to precede your identifiers with a double underscore as this is reserved for use by the system. For example __arglist is an undocumented C# keyword which is used for calling C functions which take a variable number of  arguments.

0
Himanshu Pandya

Himanshu Pandya

NA 64 16.9k 10y
Thanks