命名空间中的数字 [英] Numbers in namespace

查看:117
本文介绍了命名空间中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这四个不同的命名空间下,我有一堆类:

I have a bunch of classes under these four different namespaces:

  • a.b.c.x
  • a.b.c.y
  • a.b.c.z

两个包含"myEnum"定义的类都不在命名空间"a.b"下.我在"a.b.c.x"和"a.b.c.z"中定义了"myEnum",但出现以下错误:

Neither of the classes that contain a definition for "myEnum" are directly under namespace "a.b". I have "myEnum" defined in "a.b.c.x" and "a.b.c.z" but i get the following error:

名称空间"a.b"已经包含myEnum的定义.

The namespace 'a.b' already contains a definition for myEnum.

这是为什么?我该如何解决?

Why is this? And how can i fix it?

好,我修好了.显然,我在命名空间中不能有这样的数字"a.b.202.x".那就是它所抱怨的.有人知道为什么吗?

Well i fixed it. Apparently i cannot have numbers like this "a.b.202.x" in a namespace. that's what it was complaining about. anyone know why?

推荐答案

显然我不能有这样的数字 命名空间中的"a.b.202.x". 那就是它所抱怨的. 有人知道为什么吗?

Apparently i cannot have numbers like this "a.b.202.x" in a namespace. that's what it was complaining about. anyone know why?

不能声明int 202;的原因相同-标识符不能以C#中的数字开头.

The same reason that you can't declare int 202; - identifiers cannot begin with digits in C#.

编辑:

这是尝试通过重现特定于您的 (奇怪)编译器错误的方法.

Here's an attempt to explain your specific (strange) compiler error, by reproducing it.

以下代码:

namespace a.b
{ 
   enum myEnum {}
}     

namespace a.b.202.x
{
   enum myEnum {}
}

由于好奇(无论如何对我)错误而失败:

fails with the curious (to me anyway) errors:

{ expected  
The namespace 'a.b' already contains a definition for 'myEnum'  

推测,原因是错误的标识符使编译器将第二个名称空间声明视为格式错误",而忽略.202.x.如果是这样的话,那么在编译器中确实应该看到第二个myEnum类型在名称空间a.b中,它当然是重复的.

I speculate that the reason for this is that the bad identifier makes the compiler treat the second namespace declaration as "malformed", ignoring the .202.x. If this is so, it follows that it should indeed appear to the compiler that the second myEnum type is in the namespace a.b, which of course would be a duplicate.

如果您完全摆脱了第一个名称空间(及其中的枚举)并重新编译,您将看到第二个枚举类型的全限定名称被推断为a.b.myEnum,这进一步证明了这一点. (尽管无法编译).

This is further supported by the fact that if you get rid of the first namespace (and the enum in it) completely and recompile, you will see that the fully qualified name of the second enum-type is inferred as a.b.myEnum (despite the failure to compile).

这篇关于命名空间中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆