[inline...] On Wed, 29 May 2002 14:21:27 -0400, Shawn Wildermuth <[EMAIL PROTECTED]> wrote:
>(I searched the archives and haven't noticed this anywhere) > >Take the following classes (taken directly from the spec): > >class Base >{ > public static void F() {} >} >class Derived: Base >{ > new private static void F() {} // Hides Base.F in Derived only >} >class MoreDerived: Derived >{ > static void G() { F(); } // Invokes Base.F >} > >When I call it like: > > Derived.F(); > >I expected to get a compliation error, since Bar.Quux(...) is private >(hidden), but it calls Foo.Quux(). Per the C# spec, 10.7.1.2, Paragraph >4, Line 2: > >A declaration of a new member hides an inherited member only within the >scope of the new member. > >It seems to imply that you can overload by access, Two methods overload each other if they are declared in the same scope so Derived.F does not overload Base.F. It doesn't override it either (that's a virtual thing). It hides it. You cant overload based on access alone. The lookup is not like in C++ where the name is bound and _then_ the test to see if it's accessible is made. In C# the accessibility is considered when forming the candidate method group. >but what I wanted was >to hide the void F() from users of my Derived class. It sounds like you want to use explicit interface implementation. That allows a method to be called only through its interface. But of course your methods are static so unless you can refactor to make them instance methods that's out. HTH Jon Jagger You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.