我知道 C# 中类方法的命名约定是以大写字母开头,每个新词都是大写字母(例如 GetDeviceName)。
所以我的问题是为什么当我创建一个表单,在上面放置一个控件,然后双击该控件(对于由 IDE 自动为我创建的方法)我得到一个以非大写字母开头的方法? (例如 selectButton_Click(object sender, EventArgs e) )
最佳答案
控件的事件处理程序的命名约定一直是controlName_EventName
,所以基本上,它会重用您自己的控件命名约定,然后加上事件的名称。
这可能与一般的命名标准相反,但一直都是这样。
这样做的结果是,像 GhostDoc 这样的工具可以识别这种格式,从而生成文档,虽然仍然是通用的,但比试图自行推断方法的目的更切题。
例如,“controlName_EventName”方法可以这样记录:
/// <summary>
/// Handles the EventName event of the controlName control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance
/// containing the event data.</param>
protected void controlName_EventName(object sender, EventArgs e)
{
而不是像这样(因为 GhostDoc 处理上述问题,我根据使用错误方法名称的经验在这里即兴发挥):
/// <summary>
/// Control names the event name.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
protected void controlName_EventName(object sender, EventArgs e)
{
关于c# - 为什么 visual studio 打破了 C# 中方法的命名约定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/914280/