明确是指一类没有在C#中的命名空间是指、明确、空间

2023-09-03 00:19:46 作者:大哥没感情

在code我正在与有一类叫做环保不在任何名称空间。不幸的是,如果我在进口的系统命名空间中的类,有没有办法来指代所谓的环保自定义类。我知道这是一个不幸的选择,应该重构,但有什么办法,我可以明确地提到了冲突的班?

The code I'm working with has a class called Environment that is not in any namespace. Unfortunately if I am in a class that imports the System namespace, there is no way to refer to the custom class called Environment. I know this was an unfortunate choice and should be refactored, but is there any way I can explicitly refer to the conflicting class?

在C ++中它用似乎要做到这一点的方法是 :: ,然后在Java中有被称为什么全球:: 我如何做它在C#中?

In C++ it seems the way to do this is by using ::, and in Java there is something called global:: How do I do it in C#?

推荐答案

C#也有一个全球性的(或者未命名)命名空间 - 你可以用全球:: 来访问您的类:

C# also has a global (or unnamed) namespace - you can use global:: to access your class:

global::Environment 

请参阅有关 MSDN 。另请参阅 :: 运营商。

See more on MSDN. Also see the :: operator.

您可以创建一个别名还有:

You can create an alias for it as well:

using myEnv = global::Environment;
using sysEnv = System.Environment;