简体   繁体   中英

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM