开发者

Namespace and class conflict(?)

This is a 开发者_开发知识库bad title for the question, but I'm not quite sure of a better one.

I have a namespace called Globals with a class X in it. I also have a class called Globals. When I try to access Globals.X.StaticMember it tries to access the class Globals.X and complains that X doesn't exist. How do I reference the namespace Globals - ie ::Globals.X.StaticMember (:: doesn't compile).


Try global::Globals.X.StaticMember.

And Globals are Evil!


Eric Lippert recently blogged about it. Four blog posts no less, check it out. Start at part one.


Eric Lippert recently had a series of blogposts describing the problems you run into when using the same name for a class and a namespace, explaining this statement from the Framework Design Guidelines in section 3.4:

“do not use the same name for a namespace and a type in that namespace”.

See here for the various posts:

Do not name a class the same as its namespace (Part 1, Part 2, Part 3, Part 4)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜