开发者

Namespace and class conflict(?)

开发者 https://www.devze.com 2022-12-29 05:50 出处:网络
This is a 开发者_开发知识库bad title for the question, but I\'m not quite sure of a better one.

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

精彩评论

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