.NET类型的私有成员的命名约定 [英] Naming conventions for private members of .NET types

查看:134
本文介绍了.NET类型的私有成员的命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当我有一个类或结构体中的私有字段,我使用camelCasing,所以很明显,它是真正的私人的,当你看到它的名字,但在一些同事的C#代码,我看到他们使用 m _ 大多或有时 _ ,就像有一些惯例。

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命名约定阻止你为成员名使用下划线吗?

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.

当我是一些代码的所有者,我明确使用camelCasing对于私人成员,当他们必须对代码进行小的修改时,他们坚持它们的约定,而不是遵循任何约定。

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.

这是一个争议吗? / p>

Is this a controversy?

推荐答案

从技术上讲,下划线违反了.NET约定(或者至少以前是注释线程),但Microsoft程序员自己经常使用下划线,文档中的许多示例使用下划线。我认为能够一目了然地看到哪些变量是成员变量(字段)和哪些是本地的是非常有帮助的。下划线真的有助于这一点。

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 ---最佳实践

这里是一个含Microsoft官方推荐的页面:

And here's a page with Microsoft's official recommendations:

https://msdn.microsoft.com/en-us/library/ms229045%28v=vs.110%29.aspx

这篇关于.NET类型的私有成员的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆