我正在用 C#创建一个基于Windows 窗体的应用程序。我的表单构造函数接受 parameter string 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
它,这对我来说听起来很愚蠢。
我应该怎样命名我的变量?这种命名是否有规则?