开发者

Namespace problem

I'm working on an ASP.NET web application with .NET 3.5 and have run into the following problem:

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.

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. Any ideas?


I can't really see that there should be a problem unless you have a using statement referencing it somewhere. 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. 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.


You're working in X.Web.Controls.Core which is a subnamespace of X.Web.Controls. That means the namespace Utils in X.Web.Controls is implicitly visible.

Solve using an alias as suggested by Blixt.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜