有问题,当两个引用的程序集都定义类型A.A1 [英] Having problems when two of referenced assemblies both define type A.A1
问题描述
如果两个组件都定义了命名空间A
包含类A1
,那么这两个类都被视为独特的类型。
If two assemblies both define namespace A
containing class A1
, then the two classes are considered unique types.
A)是两个命名空间也被认为是独一无二的?
a) Are the two namespaces also considered unique?
b)若程序P
有两个程序集的引用,我们如何创建两种类型的实例?也就是说,我不断收到一个错误,当我尝试创建 A.A1
b) If program P
has a reference to both assemblies, how do we create an instances of the two types? Namely, I keep getting an error when I try to create an instance of A.A1
using A;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A1 a = new A1(); // error
}
}
}
C)但如果程序P
也定义了键入B.A1
,那么编译器不会当我宣布<$实例抱怨C $ C> A1 :
c) But if program P
also defines type B.A1
, then compiler doesn’t complain when I declare an instance of A1
:
using A;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A1 a = new A1(); // ok
}
}
class A1 { }
}
不应该抱怨编译器,因为它无法知道 A1
来使用哪个版本( A.A1
从引用的组件之一或 B.A1
)?
Shouldn’t compiler complain, since it can’t know which version of A1
to use ( A.A1
from one of the referenced assemblies or B.A1
)?
感谢名单
推荐答案
您可以用解决这个的外部别名指令。
You can resolve this with the extern alias directive.
这里是一个的更好的解释。
这篇关于有问题,当两个引用的程序集都定义类型A.A1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!