control naming conventions,

D

dragonslayer008

When I drag a control onto a form, visual studio gives it a dummy
name. I'm wondering, what are good naming conventions you use for
controls? I like to indicate the control type: for example,
"submitButton" or "showResultCheckBox". Although I find this
cumbersome sometimes.

Also, I notice that in C#/.NET code, the m_ prefix for member
variables is no longer popular, as it was in MFC. Do people use any
notation to denote member variables in C#/.NET? I don't like to
confuse them with local variables. Maybe it is popular to explicitly
reference "this"?
 
J

Jeff Gaines

On 19/09/2007 in message
<[email protected]>
When I drag a control onto a form, visual studio gives it a dummy
name. I'm wondering, what are good naming conventions you use for
controls? I like to indicate the control type: for example,
"submitButton" or "showResultCheckBox". Although I find this
cumbersome sometimes.

I still use the prefixes btn, txt, lv, lst, cbo etc. I can usually
remember what a control is but not what it is called.
Also, I notice that in C#/.NET code, the m_ prefix for member
variables is no longer popular, as it was in MFC. Do people use any
notation to denote member variables in C#/.NET? I don't like to
confuse them with local variables. Maybe it is popular to explicitly
reference "this"?

Again I still use m_. I think the modern convention is to use an
underscore but I find that confusing.
 
M

Matt Lacey

When I drag a control onto a form, visual studio gives it a dummy
name. I'm wondering, what are good naming conventions you use for
controls? I like to indicate the control type: for example,
"submitButton" or "showResultCheckBox". Although I find this
cumbersome sometimes.

Also, I notice that in C#/.NET code, the m_ prefix for member
variables is no longer popular, as it was in MFC. Do people use any
notation to denote member variables in C#/.NET? I don't like to
confuse them with local variables. Maybe it is popular to explicitly
reference "this"?

See the '.NET Framework General Reference Naming Guidelines' at
http://msdn2.microsoft.com/en-us/library/xzf533w0(vs.71).aspx
 
H

Herfried K. Wagner [MVP]

When I drag a control onto a form, visual studio gives it a dummy
name. I'm wondering, what are good naming conventions you use for
controls? I like to indicate the control type: for example,
"submitButton" or "showResultCheckBox". Although I find this
cumbersome sometimes.

If the controls are private, you can give them any name you want. If they
are part of the interface, the .NET Naming Guidelines should be used.

Also, I notice that in C#/.NET code, the m_ prefix for member
variables is no longer popular, as it was in MFC. Do people use any
notation to denote member variables in C#/.NET? I don't like to
confuse them with local variables. Maybe it is popular to explicitly
reference "this"?

Typically '_' or 'm_' are used, but it really depends on your preference
because private variables are not part of a class' interface.
 
B

Bob Powell [MVP]

If the application needs to be modified by someone else later on, if you're
working on a team for example, go ahead and name the controls for their
function even though it may seem cumbersome.

I have a little naming convention that is unofficial but has a good reason;
Backing variables for properties use the underbar followed by the lower-case
letter of the property name. I know I know, this is not CLS compliant but
hey. The reason for this is that many of my customers ask for source in VB
which I can't write because its a stupid language with really crummy
inconsistencies and miserable syntax so, I write in C# and use a converter.
If your backing variables are named for the property then VB, which is
brain-dead and non case-sensitive chokes on the private name so my
conventions are as follows.

#1 backing variables for properties = _propertyName
#2 Property declarations = PropertyName
#3 class scope variable = _variableName
#4 method scope variables = variableName

I always use a name indicative of the function and I never use m_ or c_ or
other such frippery.


--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

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.
 
P

Paul Werkowitz

Am Sat, 22 Sep 2007 12:41:36 +0200 schrieb Bob Powell [MVP]:
#1 backing variables for properties = _propertyName
#2 Property declarations = PropertyName
#3 class scope variable = _variableName
#4 method scope variables = variableName

I always use a name indicative of the function and I never use m_ or c_ or
other such frippery.
Frippery? You suggest to use an underscore, too.

IMHO the underscore is to be avoided at all.

Greetz
Paule
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top