Reputation: 14899
I have a bunch of classes under these four different namespaces:
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:
The namespace 'a.b' already contains a definition for myEnum.
Why is this? And how can i fix it?
EDIT:
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?
Upvotes: 2
Views: 2902
Reputation: 113452
Apparently i cannot have numbers like this "a.b.202.x" in a namespace. that's what it was complaining about. anyone know why?
The same reason that you can't declare int 202;
- identifiers cannot begin with digits in C#.
EDIT:
Here's an attempt to explain your specific (strange) compiler error, by reproducing it.
The following code:
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'
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.
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).
Upvotes: 6