C#中的命名空间冲突 [英] Namespace conflict in C#

查看:15
本文介绍了C#中的命名空间冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序命名空间中有一个 System 命名空间.结果,我无法从我的内部看到标准的 System 命名空间.我该如何解决这个问题?

There is a System namespace inside my program's namespace. And as a result I can't see the standard System namespace from within mine. How can I resolve this problem?

例如,在 C++ 中,有一个 :: 运算符将我转移"出我的命名空间,因此我可以看到与当前命名空间同名的外部命名空间:

For example in C++ there is the :: operator which 'shifts' me out of my namespace, so I can see external namespaces with the same name as my current namespace:

C#中有类似的运算符吗?

Is there a similar operator in C#?

推荐答案

您需要使用 global 关键字.这迫使命名空间解析从最顶部开始.它主要用于生成的代码中,以双重确保引用了正确的命名空间.

You need to use the global keyword. That forces the namespace resolution to start at the very top. It's mostly used in generated code to be doubly sure the right namespace is referenced.

 global::System.Foo.Bar;

关于它的一些 MSDN 文档:http://msdn.microsoft.com/en-us/library/c3ay4x3d.aspx

Some MSDN documentation on it: http://msdn.microsoft.com/en-us/library/c3ay4x3d.aspx

这篇关于C#中的命名空间冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆