如何获得命名空间别名操作符::在C#的工作?别名、如何获得、操作、工作

2023-09-03 04:48:43 作者:27.失心仙女

我碰到的情况不太可能发生,当我引用两个外部组件,这两个具有相同的命名空间和类型名称。当我尝试使用类型,编译器会引发一个错误,它不能解决我想用哪一个。

我看到C#提供了使用别名引用的机制。你甚至可以通过在Visual Studio 2008中引用我的code我如何使用这个别名的属性窗口中指定这些别名?据我了解,我应该使用 :: 运营商,但它失败,出现以下错误:

  

CS0432 - 别名找不到

通常的经营者不也是如此。

在输出窗口,我看到,编译器获取其命令行传递正确的别名。

在我或许可以尝试下任何指针都大大AP preciated。

解决方案

 外部别名alias1;
使用alias1 ::命名空间;
 
c 开发之is操作符

I've come up against the unlikely scenario when I reference two external assemblies that both have the same namespace and type names. When I try to use the type, the compiler throws an error that it cannot resolve which one I want to use.

I see that C# offers a mechanism to use aliases for references. You can even specify these aliases via the Property window of a reference in Visual Studio 2008. How do I use this alias in my code? As I understand, I should be using the :: operator, but it fails with the following error:

CS0432 - Alias not found

The usual . operator fails as well.

In the output window I see that the compiler gets the alias passed correctly in its command line.

Any pointers on what I may be able to try next are greatly appreciated.

解决方案

extern alias alias1;
using alias1::Namespace;