GUI,无论是用WinForms还是XAML编写,似乎在我看到的项目之间具有最广泛的命名约定.对于一个TextBox
人的名字的简单,我已经看到了各种命名约定:
TextBox tbName // Hungarian notation
TextBox txtName // Alternative Hungarian
TextBox NameTextBox // Not even camelCase
TextBox nameTextBox // Field after field with TextBox on the end
TextBox TextBoxName // Suggested in an answer...
TextBox textBoxName // Suggested in an answer...
TextBox uxName // Suggested in an answer...
TextBox name // Deceptive since you need name.Text to get the real value
TextBox textBox1 // Default name, as bad as you can get
Run Code Online (Sandbox Code Playgroud)
我通常会遵守所有.cs文件的StyleCop规则,并且看到其他人也这样做,但GUI往往会违反这些规则或变化很大.我没有看到任何专门引用GUI元素的Microsoft指南,而不仅仅是普通变量,甚至是在控制台应用程序之外应用的示例.
在GUI中命名元素的最佳实践是什么?
您使用哪种命名约定?为什么?
我喜欢使用employeeNameTextBox,因为:
注意:我使用的是全名而不是缩写(例如"tb"),因为它符合MS的命名约定,即避免使用缩写.