SLaks gives a good answer; see my comments for some additional notes.
As I said in the comments I am looking for my old notes on this subject and if I find them, I'll write a blog. Here's a fun additional example. This program is legal. Are the meanings of N
in the class declaration and the field declaration the same or different? If they are the same, what is a fully-qualified type expression for them? If they are different, why does the specification require that they be different?
public class N {}
public class B<T>
{
public class N {}
}
public class D : B<N> // base class
{
N n; // field
}
This illustrates the fundamental problem: name lookup requires that the base class is known, but the base class is looked up by name.
Now think about how interfaces work in the mix. Suppose class D
also implements an interface IN
, similarly nested in B
and available globally. Does the interface lookup resolve to the base class or the global namespace? These are the sorts of questions that you have to resolve when you're writing a compiler.