[英]Global namespace with mixed language solution
I have a VB.NET project which has project references to another VB.NET project and a C# project. 我有一个VB.NET项目,该项目具有对另一个VB.NET项目和C#项目的项目引用。 Each of the referenced assemblies defines a class with the same name, say
Class1
. 每个引用的程序集都定义了一个具有相同名称的类,例如
Class1
。 I can't in either case access it without the namespace itentifier, ie Dim c As Class1
, which would be ambiguous. 在任何情况下,如果没有名称空间Itentifier,即在
Dim c As Class1
,我都无法访问它,这将是模棱两可的。
The compiler is forcing me to use 编译器强迫我使用
Dim c As Global.C#Namespace.Class1
but Global
can be omitted for the VB.NET class 但是可以为VB.NET类省略
Global
Dim c As VBNamespace.Class1
What function is the Global
identifier serving in this case, and why only for the C# reference? 在这种情况下,
Global
标识符有什么作用?为什么只为C#引用服务? And why is it unnecessary (actually Global.VBNamespace.Class
doesn't compile) in the VB.NET case? 在VB.NET情况下为什么没有必要(实际上是
Global.VBNamespace.Class
不编译)?
There was a legacy class with the same name as the referenced C# namespace name. 有一个旧类,其名称与引用的C#名称空间名称相同。 The compiler recognized that identifier to be the class instead of the namespace in the referenced assembly.
编译器将该标识符识别为类,而不是所引用程序集中的名称空间。
The important point is that the compiler was being confused by a namespace and a class sharing the same name. 重要的一点是,编译器被名称空间和共享相同名称的类所混淆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.