在类名中使用下划线
在类名中使用 _
安全吗?
命名中 .
的最佳替代是什么? (目前我使用_
。)
Is it safe to use _
in class names?
What's the best replacement for .
in naming? (Currently I use _
.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正如其他人提到的,它是安全的。但是,Microsoft 的类命名指南如下:
正如 Jon Skeet 提到的,一个好的替代方案是将
.
替换为Dot
。例如,与drive.google.com相关的类可以命名为DriveDotGoogle
。 (我认为可以省略 DotCom 部分,以免不必要地延长名称。)As others have mentioned, it is safe. However, Microsoft's Class Naming Guidelines read:
As Jon Skeet mentioned, a good alternative would be to replace
.
withDot
. For example, a class related to drive.google.com could be namedDriveDotGoogle
. (I think the DotCom portion could be omitted so as not to unnecessarily lengthen the name.)是的,它很安全。
您甚至不应该考虑有一个“。”在类名中。我无法想象他们什么时候会出现。也许如果您想将某个东西命名为“.NET”,您可以使用“DotNet”。类名应该简洁,就我个人而言,我从未在类名中使用过下划线。我更喜欢骆驼肠衣。
您可以考虑阅读MSDN - 命名指南。
Yes, it is safe.
You should never even consider having a "." in a class name. I can't imagine when they would come up. Perhaps if you wanted to name something ".NET" you would do with "DotNet". Class names should be concise, and personally, I've never used an underscore in one. I prefer camel casing.
You may consider reading MSDN - Naming Guidelines.
对于类名,我使用 CamelCasing 而不是 _。您应该坚持一个标准,如果您正在与多个人一起处理项目,这一点尤其重要。命名约定应在解决方案/组织内保持一致
For class Names, I use CamelCasing rather than _. You should stick to one standard, this is specially important if you're working on projects with more than one person. Naming convention should be consistent within the solution / organisation
在类名中使用
_
是安全的,就像使用其他标识符一样。为什么类名中需要逻辑
.
?你能举个例子吗?It is safe to use
_
in class names, just like it is with other identifiers.Why do you need a logical
.
in your class names? Can you give an example?听起来像是您生成的 CSharp 代码。如果是这种情况,您可能需要查看 System.Design 程序集中的以下帮助程序例程:
http://msdn.microsoft.com/en-us/library/ms145952.aspx
Sounds like your generating CSharp code. If this is the case you may want to look at the following helper routine from the System.Design assembly:
http://msdn.microsoft.com/en-us/library/ms145952.aspx
一次使用一个下划线是安全的,尽管您不应该使用两个连续下划线。来自 C# 语言规范,第 2.4.2 节:
就我个人而言,无论如何,我都会尽量避免使用带下划线的类型名称...不过,我不确定“替换
.
”是什么意思。如果您能提供一些背景信息,那将会有所帮助。It's safe to do so for one underscore at a time, although you shouldn't use two consecutive underscores. From the C# language spec, section 2.4.2:
Personally I try to avoid type names with underscores anyway though... I'm not sure what you mean by "replacement for
.
" though. If you could give some context, that would help.