使用类型相同的名称和放大器;在2 .NET程序集命名空间放大器、名称、类型、程序

2023-09-04 00:19:17 作者:mascot(吉祥物)

出于好奇,我已经创建了2集这两者有一个类( 1级)完全相同的命名空间( LIBRARY1 )。然后我创建另一个客户端引用这些2组件,并尝试创建 1级的实例。

Out of curiosity, I've created 2 assemblies which both have a class (Class1) with the exact same namespace (Library1). I then create another client referencing those 2 assemblies and try to create an instance of Class1.

编译器,这并不奇怪,给了我一个编译错误有关的明确的引用。有没有什么办法来明确指定我想用避免歧义的组件类型?

The compiler, not surprisingly, gives me a compile-error about the ambiguous reference. Is there any way to explicitly specify the type in the assembly I want to use to avoid the ambiguity?

注:我知道这种情况很少,如果有的话,在所有的,发生在实践中。这只是一个问题,出于好奇语言功能。

Note: I know this rarely, if ever at all, happens in practice. It's just a question out of curiosity about language feature.

推荐答案

我认为你应该使用 EXTERN别名的包裹全局命名空间之外组装的命名空间。

I think you should use an extern alias to wrap the assembly namespaces outside of the Global namespace.