Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute/outer and inner namespace confusion in C#

Tags:

c#

using Foo.Uber;

namespace MyStuff.Foo
{
    class SomeClass{
        void DoStuff(){
            // I want to reference the outer "absolute" Foo.Uber
            // but the compiler thinks I'm refering to MyStuff.Foo.Uber
            var x = Foo.Uber.Bar();
        }
    }
}

How could I solve this? Just moving the using statement inside my namespace doesn't help.

like image 533
Qtax Avatar asked May 17 '11 13:05

Qtax


2 Answers

You can do this using a namespace alias qualifier (typically global::) to refer to the default / root namespace:

global::Foo.Uber

like image 90
sharepointmonkey Avatar answered Oct 25 '22 15:10

sharepointmonkey


Alias the namespace in the using statement:

using ThatOuterFoo = Foo.Uber;
...
...
//Some time later...
var x = ThatOuterFoo.Bar();
like image 3
Paolo Avatar answered Oct 25 '22 16:10

Paolo