Shawn, The C# Language specification on MSDN appears to be different than the one you are referencing. Here is the link on Microsoft's web site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec_3_7_1_2.asp . The section in this document is 3.7.12 (not 10.7.1.2). It uses the same example you cite below but the following text follows the example to imply that MoreDerived can invoke Base.F()
"In the example above, the declaration of F in Derived hides the F that was inherited from Base, but since the new F in Derived has private access, its scope does not extend to MoreDerived. Thus, the call F() in MoreDerived.G is valid and will invoke Base.F." Todd Clemetson |---------+----------------------------> | | Shawn Wildermuth | | | <swildermuth@ADOG| | | UY.COM> | | | Sent by: dotnet | | | discussion | | | <[EMAIL PROTECTED]| | | EVELOP.COM> | | | | | | | | | 05/29/2002 02:21 | | | PM | | | Please respond to| | | dotnet discussion| | | | |---------+----------------------------> >------------------------------------------------------------------------------------------------------------------------------| | | | To: [EMAIL PROTECTED] | | cc: | | Subject: [DOTNET] Problem with hiding derived methods | >------------------------------------------------------------------------------------------------------------------------------| (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, but what I wanted was to hide the void F() from users of my Derived class. If they want to downcast to Base and use it, so be it. Am I crazy? Even Gunnerson's book described it the way I thought it worked. Is csc wrong or am I? Thanks, Shawn Wildermuth [EMAIL PROTECTED] http://adoguy.com http://shawnwildermuth.com This e-mail is provided "AS IS" with no warranties, and confers no rights. Any outlandish claims, boasting, or obvious guesses are strictly the responsibility of the author. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.