Note that this practice isn't official because it isn't CLR compliant.
I use the following naming conventions in my code. Similar styles are used
by others;
Underbar denotes a field. Fields are ALWAYS protected or private. The name
is the same as the property name but has a preceeding underbar and a lower
case initial letter such as _myInteger
Property names use the name of the property backer variable witout the
underbar and with the initial capital letter such as MyInteger.
A property is structured so:
protected int _myInteger;
public int MyInteger
{
get{return _myInteger;}
set{_myinteger= value;}
}
All names are CamelCased
This prctice is particularly useful if you need to provide code in both C#
and VB as I do often because I can write in C# and convert to VB using a
conversion tool. If you don't use the underbar in this way VB, which is too
stupid to recognise the difference between lower-case and upper-case
characters, chokes on the names myInteger and MyInteger being the same.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Peter Kirk" <pk@alpha-solutions.dk> wrote in message
news:uM******** *****@TK2MSFTNG P12.phx.gbl...
Hi
I am looking at some C# code, and can see in some of the classes there are
instance variables whose names start with an underscore, for example:
private string _projectId;
Is there a reason for using underscores like this in C#?
Thanks,
Peter