命名空间的名称(在名称中使用_下划线) [英] Name of namespaces (using _ underscore in names)

查看:364
本文介绍了命名空间的名称(在名称中使用_下划线)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello。


在C#中创建命名空间并使用数字启动名称时,VS IDE会通过在数字前添加下划线(_)来重命名命名空间。这是因为用数字开始命名空间名称是不可能的。


但是这个下划线是否仍会导致冲突?或者使用它是否安全?


我的问题是我需要根据每年创建名称空间,例如:Accounts._2017。是否可以使用此名称或是否有人建议使用名称Accounts.Y2017或类似名称(在开头使用字母而不是下划线?




SigurðurH Alfhildars

解决方案

只要编译器认为命名空间名称合法并且可以编译程序,就可以将命名空间名称命名为任何名称。所以VS是前缀它带有一个"_",然后就是它要做的事情。"_"可以用于本地
变量名,_sandri81或_81sandri表示它是类或方法的本地。

Hello.

When you create a namespace in C# and start the name with number, the VS IDE rename the namespace by putting underscore (_) before the numbers. It's because it's not possible to begin namespace names with numbers.

But does this underscore still cause conflicts? Or is it safe to use it?

My problem is that I need to create namespaces based on each year, for example: Accounts._2017. Is it OK to use this name or does someone recommend to use the name Accounts.Y2017 or similar (using letter instead of underscore in the beginning?


Sigurður H Alfhildars

解决方案

You can name the namespace name anything you want as long as the compiler considers it legal and can compile the program. So of VS is prefixing it with an " _",  then that's something it's going to do. "_" can be used for local variabke name, _sandri81 or _81sandri signifying that it local to the class or method.


这篇关于命名空间的名称(在名称中使用_下划线)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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