简体   繁体   English

命名空间和类冲突(?)

[英]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. 我有一个名为Globals的命名空间,其中包含一个类X. I also have a class called Globals. 我还有一个名为Globals的课程。 When I try to access Globals.X.StaticMember it tries to access the class Globals.X and complains that X doesn't exist. 当我尝试访问Globals.X.StaticMember时,它尝试访问Globals.X类并抱怨X不存在。 How do I reference the namespace Globals - ie ::Globals.X.StaticMember (:: doesn't compile). 我如何引用命名空间Globals - 即:: Globals.X.StaticMember(::不编译)。

Try global::Globals.X.StaticMember . 尝试global::Globals.X.StaticMember

And Globals are Evil! 而Globals是邪恶的!

Eric Lippert recently blogged about it. Eric Lippert最近在博客上写了这篇文章。 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: Eric Lippert最近有一系列博客文章描述了在为类和名称空间使用相同名称时遇到的问题,并在第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 ) 不要将类命名为与其命名空间相同第1 部分第2 部分第3 部分第4部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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