473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Naming Conventions

Ted

I'm trying to come up with naming conventions for my
company as we move to C#. I'm looking through the Naming
Guidelines section on MSDN, but I'm unable to find a
recommendation for class scope variables.

Working with WinForms, I believe it would be helpful to
have some type of prefix. In Visual Basic we used
m_variableName. But I can't find any suggestions on this.

Any help on this would be great. Thanks,
Ted
Jul 21 '05 #1
5 1864
Hi Ted

Microsoft suggests the following:

Public methods or properties are pascal cased. (mixed case - first letter
upper case)
Private or protected methods are camel cased. (mixed case - first letter
lower case)
Private or protected fields (variables) are camel cased and prefixed with an
underscore.
Variable names do not use Hungarian notation.
Parameters are camel cased.

Public Class TestClass
Private _stringField1 As String
Protected _stringField2 As String

' public fields are not recommended
' use properties instead
Public StringField3 As String

Public Property StringField1() As String
Get
Return _stringField1
End Get
Set(ByVal Value As String)
_stringField1 = Value
End Set
End Property

Public Sub CoolRoutine1(ByVal param1 As String)
End Sub

Private Sub coolRoutine2()
End Sub
End Class

There's a MSDN Webcast on .NET Best Pratices that discusses this over a few
slides.

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada

"Ted" <an*******@discussions.microsoft.com> wrote in message
news:14*****************************@phx.gbl...

I'm trying to come up with naming conventions for my
company as we move to C#. I'm looking through the Naming
Guidelines section on MSDN, but I'm unable to find a
recommendation for class scope variables.

Working with WinForms, I believe it would be helpful to
have some type of prefix. In Visual Basic we used
m_variableName. But I can't find any suggestions on this.

Any help on this would be great. Thanks,
Ted

Jul 21 '05 #2
Cor
Hi Rob,

I have checked for it in the VB.resourcekit and there is this what you show
absolute not used in the best practise sample, so you make me curious.

Also because the type of a object is very good to recognise in dotnet it is
advice to add that not in your dataname, so I am very curious.

Can you give me the link to that documentation.

Cor
Hi Ted

Microsoft suggests the following:

Public methods or properties are pascal cased. (mixed case - first letter
upper case)
Private or protected methods are camel cased. (mixed case - first letter
lower case)
Private or protected fields (variables) are camel cased and prefixed with an underscore.
Variable names do not use Hungarian notation.
Parameters are camel cased.

Public Class TestClass
Private _stringField1 As String
Protected _stringField2 As String

' public fields are not recommended
' use properties instead
Public StringField3 As String

Public Property StringField1() As String
Get
Return _stringField1
End Get
Set(ByVal Value As String)
_stringField1 = Value
End Set
End Property

Public Sub CoolRoutine1(ByVal param1 As String)
End Sub

Private Sub coolRoutine2()
End Sub
End Class

There's a MSDN Webcast on .NET Best Pratices that discusses this over a few slides.

Jul 21 '05 #3
Ted

Rob,

Can you send me a link where this is suggested?

In the Design Guidelines for Class Library Developers
microsoft is very inconsistent with naming conventions
while suggesting proper naming conventions.

For example, at http://msdn.microsoft.com/library/en-
us/cpgenref/html/cpconpropertyusageguidelines.asp?
frame=true

Microsoft lists the example:

[Visual Basic]
Public Class TextBox
Private m_dataSource As String
Private m_dataField As String
Private m_active As Boolean

Public Property DataSource() As String
Get
Return m_dataSource
End Get
Set (...more)

What is the "m_" prefix? If it's for Module, then module
has a different meaning in .net.

The C# example:

public class TextBox
{
string dataSource;
string dataField;
bool active;

public string DataSource
{
get
{
return dataSource;
}
set (...more)

Now for C# they do not use the prefix.

But what if the constructor accepted the dataSource
variable in the C# example, what would the variable name
for the constructor be? ie. localDataSource or
thisDataSource?

Rob, I like your example of prefixing with the underscore
and will probably go with this, but I just can not find
that recommendation on Microsoft's website in the
guidelines section.

Thank you,
Ted
-----Original Message-----
Hi Ted

Microsoft suggests the following:

Public methods or properties are pascal cased. (mixed case - first letterupper case)
Private or protected methods are camel cased. (mixed case - first letterlower case)
Private or protected fields (variables) are camel cased and prefixed with anunderscore.
Variable names do not use Hungarian notation.
Parameters are camel cased.

Public Class TestClass
Private _stringField1 As String
Protected _stringField2 As String

' public fields are not recommended
' use properties instead
Public StringField3 As String

Public Property StringField1() As String
Get
Return _stringField1
End Get
Set(ByVal Value As String)
_stringField1 = Value
End Set
End Property

Public Sub CoolRoutine1(ByVal param1 As String)
End Sub

Private Sub coolRoutine2()
End Sub
End Class

There's a MSDN Webcast on .NET Best Pratices that discusses this over a fewslides.

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada

"Ted" <an*******@discussions.microsoft.com> wrote in messagenews:14*****************************@phx.gbl...

I'm trying to come up with naming conventions for my
company as we move to C#. I'm looking through the Naming Guidelines section on MSDN, but I'm unable to find a
recommendation for class scope variables.

Working with WinForms, I believe it would be helpful to
have some type of prefix. In Visual Basic we used
m_variableName. But I can't find any suggestions on this.
Any help on this would be great. Thanks,
Ted

.

Jul 21 '05 #4
Hi,
The convention suggested by Rob has been defined in the book "Inside C#" by Tom Archer, Microsoft Press.

The link you mentioned seems to be going along with the conventions listed in the book, and by Rob. Only exception being the private variables, which are prefixed by 'm_'.

So clases have names like: ClassName
Methods: MethodName
Properties: PropertyName
Private Attributes: m_attributeName
Other Attributes: attributeName

Regards,
Jaswinder
Jul 21 '05 #5
Cor
Hi Jaswinder,

I follow this thread also, and it is in my opinion not true what you write.

Rob is giving to stringvalues very clear the name
stringName

In my opinion Name is enough

Cor
Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Cristof Falk | last post by:
I wanted to get a feel. The documentation gives naming conventions for public/protected members. Is this truly widely adopted? And what about using the same conventions for private members and...
7
by: cmiddlebrook | last post by:
Hi there, I keep finding myself getting inconsistent with naming conventions for things like member variables, class names etc and I just want to find something that suits me and stick to it. I...
1
by: clintonG | last post by:
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and...
4
by: Mark Broadbent | last post by:
stupid question time again to most of you experts but this is something that continually bothers me. I am trying to get into the habit of naming variables and controls in an assembly as per...
3
by: clintonG | last post by:
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and...
5
by: rastaman | last post by:
Hi all, I know of the existence of Object Naming Conventions for Visual Basic 6. Now I'm reading some books about VB .NET, but the names used for the objects are button1, picturebox1, etc. I...
4
by: Patrick | last post by:
what are the general naming conventions for vb.net controls. esp txtUserName, lblPassword, btnSubmit What are the prefixes for the controls???? I've tried to search hi and low on the net, but...
9
by: kevininstructor | last post by:
Greetings, I am in the process of creating naming conventions for VB.NET controls i.e. CheckBox -> chkShowThisOnStartup ListBoxt -> lstSomeList What I am looking for other developers...
35
by: Smithers | last post by:
Is it common practise to begin the name of form classes with "frm" (e.g., frmOneForm, frmAnotherForm). Or is that generally considered an outdated convention? If not "frm" what is a common or...
1
by: Philipp Post | last post by:
Marcello, Not a big surprise as naming conventions have a lot to do with personal prefernces. There are a lot of threads in comp.databases and the other database groups. Just do a search for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.