Share via


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