C# でWindows フォームベースのアプリケーションを作成しています。私のフォームのコンストラクターは parameterstring titleを受け取り、その値をstring this.Title属性に保存し、最後に windows label を作成しますLabel this.Title。
問題は明らかです。私のLabelとstringは同じ名前で、C# の命名規則に興味があります。私は何をすべきか?
完全なコードは次のとおりです。
// BNForm.cs
public partial class BNForm : Form
{
public string Title;
public BNForm(string title)
{
this.Title = title;
InitControls();
}
}
// BNForm.Designer.cs
partial class BNForm
{
private Label Title;
private InitControls()
{
this.Title = new Label();
this.Title.Text = this.Title; // Trying to access the string here
this.Title.AutoSize = true;
this.Title.Location = new Point(15, 15);
this.Controls.Add(this.Title); // Trying to access the Label here
}
}
最初に自分のラベル変数label_Titleを呼び出しましたが、後で新しい変数を追加する必要があります。Button[] Buttonsこれは と呼ばれる必要がありますbuttonArray_Buttons。これはばかげているように思えます。
変数の名前は何にするべきですか? このようなネーミングにもルールはありますか?