[英]Namespace problem
I'm working on an ASP.NET web application with .NET 3.5 and have run into the following problem: 我正在使用.NET 3.5开发ASP.NET Web应用程序,并且遇到了以下问题:
I'm working with a class under the namespace X.Web.Controls.Core
which references the class Utils
in the namespace X.X2.components.util
. 我与命名空间下的一类工作
X.Web.Controls.Core
它引用的类Utils
命名空间中的X.X2.components.util
。
I get an error that Utils
is already defined in the namespace X.Web.Controls.Utils
This should not be possible since I can't find anything referencing that namespace from the class I'm working on. 我收到一个错误消息,名称空间
X.Web.Controls.Utils
已经定义了Utils
,这是不可能的,因为我无法从正在使用的类中找到任何引用该名称空间的东西。 Any ideas? 有任何想法吗?
I can't really see that there should be a problem unless you have a using
statement referencing it somewhere. 除非您有在某处引用它的
using
语句,否则我真的看不到应该有问题。 Do take care that code in a namespace will implicitly "see" classes in the same namespace, even if they're defined elsewhere. 请注意,命名空间中的代码将隐式“查看”同一命名空间中的类,即使它们是在其他位置定义的也是如此。
Anyways, you can solve your problem by changing the class name (for the current code file only): 无论如何,您可以通过更改类名称(仅对于当前代码文件)解决问题:
using X2Utils = X.X2.components.util.Utils;
The class will be named X2Utils
in your code. 该类在您的代码中将命名为
X2Utils
。 Alternatively you can make a shortcut for its namespace: 另外,您可以为其命名空间创建快捷方式:
using X2util = X.X2.components.util;
Now you can refer to the class using X2util.Utils
. 现在,您可以使用
X2util.Utils
引用该类。
You're working in X.Web.Controls.Core which is a subnamespace of X.Web.Controls. 您正在使用X.Web.Controls.Core,它是X.Web.Controls的子命名空间。 That means the namespace Utils in X.Web.Controls is implicitly visible.
这意味着X.Web.Controls中的名称空间Utils是隐式可见的。
Solve using an alias as suggested by Blixt. 根据Blixt的建议使用别名进行求解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.