Accessibility level?

public class x {
internal struct y { }
protected internal x(y param) {}
}

This gives the error that the type y is less accessible than the constructor. But I believe that internal is more accessible than protected internal. If I make the constructor internal only, it compiles. I'd think it's trivial that adding protected to it makes it less accessible, so why the error That struct really needs to be internal and that constructor really needs to be protected, is there a way to do it or is this a compiler bug



Answer this question

Accessibility level?

  • cheekydevill

    No protected internal is more accessible. With PI you are allowing any type in the current assembly and any type that derives from x to access the member. With internal you are limiting access only to the assembly types. The problem lies in that y is internal but you are using it as a parameter to a PI method. If this were allowed then derived types in other assemblies would be unable to access y because it is internal. You should mark y as protected internal. If y doesn't serve much purpose for derived types then I'd recommend removing it altogether and/or using a nested method that derived types could override.

    Michael Taylor - 6/1/06


  • Accessibility level?