Why 'A' denotes namespace?

A

Alex Sedow

Why MSVC# compiler in this error example say that 'A' is a namespace?
'A' is a class, not a namespace.

// lookup5.cs
namespace Lookup
{
namespace Case5
{
class D : B
{
T x;
}
}
namespace Case5
{
using Case5.N.N2.N3;
class B : A // error CS0118: 'A' denotes a 'namespace' where a
'class' was expected
{}
}
namespace Case5
{
namespace N
{
namespace N2
{
namespace N3
{}
}
class A
{
public class T
{}
}
}
}
}

Alex.
 
M

mikeb

Alex said:
Why MSVC# compiler in this error example say that 'A' is a namespace?
'A' is a class, not a namespace.

When I paste your sample into a stand-alone C# file, I get:

CS0246: The type or namespace name 'A' could not be found (are
you missing a using directive or an assembly reference?)

The problem here that the namespace in the using directive you have
right before attempting to use class 'A' does not contain class 'A':

using Case5.N.N2.N3; // there is no class 'A' in N3

you'd need to change it to:

using Case5.N; // or: using N;

since 'A' is in that namespace (or you could use a fully qualified name
for 'A').

maybe you're getting CS0118 instead of CS0246 because you're referencing
an assembly that has a namespace 'A'.
 
M

Mattias Sjögren

Alex,
Why MSVC# compiler in this error example say that 'A' is a namespace?

Which version? None of the CSC compiler versions I have here says
that. Instead I get

lookup5.cs(13,19): error CS0246: The type or namespace name 'A' could
not be found (are you missing a using directive or an assembly
reference?)
lookup5.cs(7,13): error CS0246: The type or namespace name 'T' could
not be found (are you missing a using directive or an assembly
reference?)

which makes perfect sense to me. Are you sure you don't have a
namespace A somewhere else in your code?



Mattias
 
A

Alex Sedow

Are you sure you don't have a
namespace A somewhere else in your code?

Mattias

I understand problem. Another file contain (in global namespace):

namespace A.B
{

}

And when C# lookup algorithm fails to find Case5 scope than it ignore using
directive and found A in global namespace.

Thanks to all. Subject is closed.

Alex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top