对于.NET类型的私有成员命名规则 [英] Naming conventions for private members of .NET types
问题描述
通常,当我有一个类或结构内的私人领域,我用驼峰规则,所以这将是显而易见的,当你看到它的名字是确实私有的,但在我的一些同事的C#code ,我看到他们用米_
大部分或有时 _
,像有某种约定的。
Normally when I have a private field inside a class or a struct, I use camelCasing, so it would be obvious that it's indeed private when you see the name of it, but in some of my colleagues' C# code, I see that they use m_
mostly or sometimes _
, like there is some sort of convention.
是不是.NET使用下划线的成员名字命名惯例prevent你?
Aren't .NET naming conventions prevent you from using underscores for member names?
而当你提到的MS命名约定或什么不是,他们告诉你他们是最好的方式,但没有解释其背后的原因。
And when you mention the MS naming conventions or what not, they tell you theirs is the best way, but don't explain the reasoning behind it.
此外,当我的一些code,其中我清楚地使用驼峰规则的私有成员,主人时,他们有稍作修改了code,他们在公约坚持,而不是下面的任何约定在那里。
Also when I am the owner of some code, where I clearly use camelCasing for private members, when they have to make a minor modification to the code, they stick in their conventions instead of following whatever conventions are there.
这是一个争议?
推荐答案
从技术上讲,下划线是违反.NET约定的(或至少曾经是 - 看评论跟帖),但微软程序员自己经常使用下划线,并且许多例子中的文档使用下划线。我认为这是非常有用的,以便能够一眼看出哪些变量是成员变量(字段),哪些是本地的。下划线确实有助于这一点。这也很好地分隔在智能感知,从局部变量私有成员变量。
Technically, underscores are a violation of .NET conventions (or at least used to be -- see comment thread), but Microsoft programmers themselves often use underscores, and many examples in the documentation use underscores. I think it's very helpful to be able to see at a glance which variables are member variables (fields) and which are local. The underscore really helps with this. It also nicely separates private member variables from local variables in intellisense.
请看到这个非常有用的页面,.NET命名约定:
Please see this very useful page for .NET naming conventions:
的http://10rem.net/articles/net-naming-conventions-and-programming-standards---best-practices
下面是微软的官方建议的页面:
And here's a page with Microsoft's official recommendations:
https://msdn.microsoft。 COM / EN-US /库/ ms229045%28V = vs.110%29.aspx
这篇关于对于.NET类型的私有成员命名规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!