简体   繁体   English

私有方法C#的名称约定-Visual Studio 2017

[英]Name convention for private methods C# - Visual Studio 2017

I have just installed a new version of Visual Studio 2017 and the studio recommends me, that I should use Pascal case for private methods (void PrivateMethod()). 我刚刚安装了新版本的Visual Studio 2017,并且该工作室向我建议,我应将Pascal大小写用于私有方法(void PrivateMethod())。 Everything is okay, it's just the name convention. 一切都很好,这只是名称约定。 I use usually Camel case (void privateMethod()). 我通常使用Camel大小写(避免使用privateMethod())。 I don't intend change my style. 我不打算改变我的风格。

However why does the Visual Studio 2017 generate the private methods for FormsApp wrong by their name convention? 但是,为什么Visual Studio 2017会因其名称约定而错误地为FormsApp生成私有方法? -> private void button3_Click(object sender, EventArgs e) Then it recommends me I should change the name to Button3_Click. -> private void button3_Click(object sender,EventArgs e)然后它建议我将名称更改为Button3_Click。

It's nothig important but I'm just curious about that. 这不是很重要,但我对此感到很好奇。 Probably a mistake on the Microsoft's side? 微软方面可能是一个错误?

VS 2017 lets you specify the code style you want. VS 2017可让您指定所需的代码样式。

Look for Tools > Options > Text Editor > C# > Code Style > Naming 查找工具>选项>文本编辑器> C#>代码样式>命名

The 'Manage Styles' button lets you add a "lowerPascalCase" style, and the '+' button lets you add a new rule that uses that style for Private Methods. “管理样式”按钮可让您添加“ lowerPascalCase”样式,而“ +”按钮可让您添加使用该样式用于私有方法的新规则。 The 'Severity' column lets you determine how draconian the enforcement of the rule should be. 通过“严重性”列,您可以确定规则执行的严格程度。

Make sure to sort your new rule above the 'Non-Field Members' in the list. 确保在列表中的“非现场成员”上方对新规则进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM