VBForums >
.NET >
C# > [RESOLVED] Class Member Variables Naming Convention
Click to See Complete Forum and Search --> : [RESOLVED] Class Member Variables Naming Convention
steve65
Apr 24th, 2006, 07:50 AM
Microsoft recommends using something like below for your class naming conventions.
public class Customer
{
string name;
public string Name
{
set
{
name = value;
}
get
{
return name;
}
}
}
Does anyone know why Microsoft wanted to get away from using the m_? It makes it a bit easier to read and know if you see that m_ it is a class variable.
public class Customer
{
string m_name;
public string Name
{
set
{
m_name = value;
}
get
{
return m_name;
}
}
}
Your thoughts please?
jmcilhinney
Apr 24th, 2006, 09:30 AM
The idea is to use names that describe the data, not the variable. The IDE can tell you what you need to know about the variable by mousing over it. Personally, I always qualify my member variables with 'Me' (VB) or 'this' (C#) when I use them anyway. Most of what I've read on MSDN suggests that what convention you use for private variables is of little consequence anyway. They are more concerned with the public interface and that it conforms to what's used in the rest of the Framework.
Bombdrop
Apr 24th, 2006, 10:12 AM
comming from VB6 and using hungairan notation I found it hard to move way from at first, but now making sure i use more discriptive names for the object(varibale) makes more sence. the following document gives a good account of coding style in .Net focusng on C#
Conding style (http://www.icsharpcode.net/TechNotes/SharpDevelopCodingStyle03.pdf)
Hope this helps!!!
:wave: :thumb: :wave:
steve65
Apr 24th, 2006, 11:50 AM
Thanks for the replies. For right now I'll stick with the using the first example.
Briantcva
Apr 24th, 2006, 12:53 PM
I find it's nice to have private class variables prefixed w/ an underscore - it's a nice heads up re: what you're using.
techgnome
Apr 24th, 2006, 12:58 PM
I use the _ method too for private variables. That way I know for sure if I'm accessing the variable directly or through the property.
-tg
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.