プロパティの名前付けのガイドライン

次の規則は、プロパティに名前を付けるときのガイドラインを示しています。

  • プロパティ名には、名詞または名詞句を使用します。
  • Pascal 形式を使用します。
  • ハンガリー表記法は使用しないでください。
  • 基になる型と同じ名前でプロパティを作成するようにしてください。たとえば、Color という名前のプロパティを宣言する場合は、このプロパティの型も同様に Color であることが必要です。このトピックの下記の例を参照してください。

次のコード例は、プロパティの適切な名前付けを示しています。

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.
   }
}

型と同じ名前のプロパティを作成するコード例を次に示します。

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.} 
   }
}

プロパティ Color の型が 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.}  
   }
}

この不適切な例では、Color 列挙体のメンバを参照できません。Color.Xxx は、Color プロパティ (Visual Basic では Integer 型、C# では int 型) の値を取得した後、その値のメンバ (System.Int32 のインスタンス メンバ) にアクセスするメンバへのアクセスであると解釈されてしまいます。

参照

クラス ライブラリ開発者向けのデザイン ガイドライン | プロパティの使用方法のガイドライン