In case the title is not completely self-explanatory, here's the code that puzzles me:
public interface IFoo<T>
{
}
public class MyClass : IFoo<MyClass.NestedInMyClass>
{
private class NestedInMyClass
{
}
}
I'm suprised this compiles with no error. It feels like I'm exposing a private
type. Shouldn't this be illegal?
Maybe your answers will simply be "There's no rule against that, so why wouldn't it be OK?" Perhaps it's equally surprising that MyClass.NestedInMyClass
is even in "scope". If I remove the MyClass.
qualification, it will not compile.
(If I change IFoo<>
into a generic class, which should then become base class of MyClass
, this is illegal, for a base type must be at least as accessible as the type itself.)
I tried this with the C# 4 compiler of Visual Studio 2010.