private field and public property naming conventions

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Adam Tatusko, MCSD, MCAD, MCDBA, MCSE, MCSA (adamtatusko_at_hotmail.com)
Date: 01/24/05


Date: 24 Jan 2005 12:49:45 -0800

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/default.asp?url=/library/en-us/cpgenref/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



Relevant Pages

  • Re: Getting Windows Display Name
    ... Private Type WKSTA_USER_INFO_1 ... usri3_script_path As Long 'Pointer to a Unicode string specifying the path for the user's logon script file. ... Dim bufptr As Long ... Public Property Get PasswordAgeAs Long ...
    (microsoft.public.access.modulesdaovba)
  • Private Class Variables Visible in Object Explorer
    ... All 3 objects' module level private ... Private strDestPath As String ... Public Property Let SetID(ByVal vNewValue As Date) ...
    (microsoft.public.access.modulesdaovba)
  • Re: common dialog w/api instead of COMDLG32.OCX, possible?
    ... As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As ... Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias ... Public Property Get FileNameAs String ...
    (microsoft.public.vb.winapi)
  • Re: How can I use a collection inside a class?
    ... Private mcTemplate As String ... Private Sub Class_Initialize ... Public Property Let Name ...
    (microsoft.public.excel.programming)
  • Re: XmlSerializer instantiation error
    ... > Private mLayerName As String ... > Private mUserDefined As Boolean ... > Public Property NumberOfBreaks() As Integer ...
    (microsoft.public.dotnet.xml)