Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

explicitly refer to a class without a namespace in C#

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?

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#?

like image 804
JoelFan Avatar asked May 04 '10 18:05

JoelFan


2 Answers

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

global::Environment  

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; 
like image 62
Oded Avatar answered Oct 08 '22 14:10

Oded


Should be global::Environment just like in Java

like image 20
Kristian Hebert Avatar answered Oct 08 '22 14:10

Kristian Hebert