Property Naming Guidelines
This page is specific to:.NET Framework Version:1.1
.NET Framework General Reference
Property Naming Guidelines

The following rules outline the naming guidelines for properties:

  • Use a noun or noun phrase to name properties.
  • Use Pascal case.
  • Do not use Hungarian notation.
  • Consider creating a property with the same name as its underlying type. For example, if you declare a property named Color, the type of the property should likewise be Color. See the example later in this topic.

The following code example illustrates correct property naming.

Public Class SampleClass 
   Public Property BackColor As Color
      ' Code for Get and Set accessors goes here.
   End Property
End Class
[C#]
public class SampleClass
{
   public Color BackColor 
   {
      // Code for Get and Set accessors goes here.
   }
}

The following code example illustrates providing a property with the same name as a type.

Public Enum Color 
   ' Insert code for Enum here. 
End Enum
Public Class Control 
   Public Property Color As Color
      Get
         ' Insert code here.
      End Get 
      Set
         ' Insert code here.
      End Set
   End Property
End Class
[C#]
public enum Color 
{
   // Insert code for Enum here.
}
public class Control 
{
   public Color Color 
   { 
      get {// Insert code here.} 
      set {// Insert code here.} 
   }
}

The following code example is incorrect because the property Color is of type Integer.

Public Enum Color 
   ' Insert code for Enum here. 
End Enum
Public Class Control 
   Public Property Color As Integer
      Get
         ' Insert code here.
      End Get 
      Set
         ' Insert code here.
      End Set
   End Property
End Class
[C#]
public enum Color {// Insert code for Enum here.}
public class Control 
{
   public int Color 
   { 
      get {// Insert code here.} 
      set {// Insert code here.}  
   }
}

In the incorrect example, it is not possible to refer to the members of the Color enumeration. Color.Xxx will be interpreted as accessing a member that first gets the value of the Color property (type Integer in Visual Basic or type int in C#) and then accesses a member of that value (which would have to be an instance member of System.Int32).

See Also

Design Guidelines for Class Library Developers | Property Usage Guidelines

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View