private field and public property naming conventions

  • Thread starter Thread starter Adam Tatusko, MCSD, MCAD, MCDBA, MCSE, MCSA
  • Start date Start date
A

Adam Tatusko, MCSD, MCAD, MCDBA, MCSE, MCSA

Has anyone found any naming convention guidelines for private fields
and public properties in Visual Basic .NET and C#.

Below is what I currently do in each of the languages. Any comments?

I would like to use the same convention in C# as in Visual Basic .NET
with camelCasing for private fields and PascalCasing for public
properties, but since Visual Basic .NET is case insensitive, I have to
use a different name for the public property and its associated private
field (e.g. add "m_" for private field). Any suggestions or
documentation from Microsoft. The Design Guidelines for Class Library
Developers at:

http://msdn.microsoft.com/library/d...ef/html/cpconnetframeworkdesignguidelines.asp

does not provide much advice on this issue. Also is there any
guidelines on when this and Me should be used to fully qualify a public
or private member?

// C#
public class Test
{
private string myVariable;

public string MyVariable
{
get
{
return myVariable;
}
set
{
myVariable = value;
}
}
}

' Visual Basic .NET
Public Class Test
Private m_myVariable As String

Public Property MyVariable() As String
Get
Return m_myVariable
End Get
Set(ByVal value As String)
m_myVariable = value
End Set
End Property
End Class
 
I generally use _camelCase for all internal variables (private), whether C#
or VB.NET. I find it easier to understand where something came from. There
are still instances where it causes problems, in VB only, but it is a decent
guideline (no matter what the standards say).
---
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************
Think outside the box!
************************************
 
Back
Top