I keep looking for this but can't find it. What naming convention is standard for objects that are instantiated?
Printable View
I keep looking for this but can't find it. What naming convention is standard for objects that are instantiated?
Maybe I'm missing it, but it looks like they don't mention a naming convention for objects created from a class. I've been using camel casing, but I've also seen an "o" prefix used. For example:
XmlDocument() xmlDoc = new XmlDocument();
XmlDocument oXmlDoc = new XmlDocument();
The convention is to use Camel Case for all local variables and method parameters, so your first example would be OK.
The second example is Hungarian notation and is specifically not recommended in .NET (it says this in the guidelines). See here.
For member variables the conventions may be more relaxed so it is quite common to use a leading _.
You'll find that there are various naming conventions elsewhere on the web but the basics tend to be similar to Microsoft's recommendations.
It's probably due to the fact that a lot of C# devs were previously Visual C++ devs and MFC apps. had an m_ naming convention for member variables.
We don't really need it but some sort of convention is just a convenience for distinguishing between the use of a local variable and a member variable (or in .NET's terminology a field).
In Java it's more common to write this.x = x for example if you're assigning to a field within a method. Strictly-speaking this is preferred but not often favoured in .NET circles. Personally it's not something I'm hung up on. Adherence to the general Camel and Pascal naming conventions are more important.