如果名称重复,如何访问根类?

Eri*_*Yin 0 c# asp.net class root

检查这个简单的样本:

public class Someone{       // [the:A]
}

public class Another{
    public class Someone{   // [the:B]
    }

    public class DoSomething{
        **how can I access Someone in root, which is [the:A]**?
    }
}
Run Code Online (Sandbox Code Playgroud)

Dai*_*Dai 5

使用"global ::"关键字,或使用using; 在顶部的声明.

global::YourNamespace.Someone
Run Code Online (Sandbox Code Playgroud)

或者,在您的使用声明中:

using SomeoneRoot = YourNamespace.Someone;
Run Code Online (Sandbox Code Playgroud)

如果您的命名空间中存在歧义,那么global ::关键字也可以在那里使用:

using SomeoneRoot = global::YourNamespace.Someone;
Run Code Online (Sandbox Code Playgroud)