By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,406 Members | 1,353 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,406 IT Pros & Developers. It's quick & easy.

naming guidelines for variables

P: n/a
Does Microsoft have any naming guidelines for variables? I've been
reading their guidelines for just about every other type (methods,
parameters, properties, etc.) but nothing about variables. Are variables
treated the same as parameters (i.e., camel case)?

I notice that Hungarian notation is being done away with.

Also, is it good practice to use an underscore to begin the name of a
field? I've seen that, and it seems like a good idea, but I didn't know
if that wasn't part of the suggested guidelines either.

Thanks,
John
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Microsoft has only provided naming guidelines for your public API -
which would be your public classes, interfaces, methods, etc. Local
variables, private fields, and even private methods and classes can be
named however you want. The naming guidelines are not to make your
internal source code more readable, they are intended to make your
consumer's source code more readable, by making your API consistent with
other .NET components.

There is no Microsoft recommended guideline (that I have seen) regarding
private variables or fields. Some people like an underscore prefix,
some like "m_", some just prefer using the same name as the public
property, just camelCased, instead of PascalCased (and prefixed with
"this." to avoid conflict with a similarly named method parameter).
Bottom line is that the decision is up to you. Decide on a standard
that you and your team are comfortable with and stick to it.


John Salerno wrote:
Does Microsoft have any naming guidelines for variables? I've been
reading their guidelines for just about every other type (methods,
parameters, properties, etc.) but nothing about variables. Are variables
treated the same as parameters (i.e., camel case)?

I notice that Hungarian notation is being done away with.

Also, is it good practice to use an underscore to begin the name of a
field? I've seen that, and it seems like a good idea, but I didn't know
if that wasn't part of the suggested guidelines either.

Thanks,
John

Nov 17 '05 #2

P: n/a
John Salerno wrote:
Also, is it good practice to use an underscore to begin the name of a
field? I've seen that, and it seems like a good idea, but I didn't
know if that wasn't part of the suggested guidelines either.


It's not necessarily good or bad. If it helps you, it's fine.

As a former C++ programmer, it bothers me, as a user-defined name
beginning with an underscore would be illegal according to the C++ Standard,
but there's no reason why that should hold sway in C# code.
--
Truth,
James Curran [erstwhile-MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Nov 17 '05 #3

P: n/a
> Does Microsoft have any naming guidelines for variables? I've been reading
their guidelines for just about every other type (methods, parameters,
properties, etc.) but nothing about variables. Are variables treated the
same as parameters (i.e., camel case)?


Take a look at

http://msdn.microsoft.com/library/de...guidelines.asp

--
..Net Reporting tool: http://www.neodatatype.net
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.