<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Hide and seek</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/06/14/hide-and-seek.aspx</link><description>Another interesting question from StackOverflow. That thing is a gold mine for blog topics. Consider the following: 
 class B { public int X() { return 123; } } class D : B { new protected int X() { return 456; } } class E : D { public int Y() { return</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Hide and seek</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/06/14/hide-and-seek.aspx#10027194</link><pubDate>Fri, 18 Jun 2010 17:14:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10027194</guid><dc:creator>Patrick</dc:creator><description>&lt;p&gt;&amp;quot;So what is the recommended way for a subclass to hide a function from the base class? A public implementation that throws an exception when called?&amp;quot;&lt;/p&gt;
&lt;p&gt;I have no idea if this is a recommended way (I doubt it is) but here goes.&lt;/p&gt;
&lt;p&gt;Use &amp;quot;new&amp;quot; to hide the method. In you new method throw the error. Then apply the EditorBrowsableAttribute on the method to hide it from intellisense. If it is not in intellisense then it does not exist right =). You do not get a compile time error but this may get you 90% of the way there.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10027194" width="1" height="1"&gt;</description></item><item><title>re: Hide and seek</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/06/14/hide-and-seek.aspx#10026151</link><pubDate>Wed, 16 Jun 2010 22:37:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10026151</guid><dc:creator>Maciej</dc:creator><description>&lt;p&gt;oReally here is something about scope, declaration space and lifetime.:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/b/ericlippert/archive/2009/08/03/what-s-the-difference-part-two-scope-vs-declaration-space-vs-lifetime.aspx"&gt;blogs.msdn.com/.../what-s-the-difference-part-two-scope-vs-declaration-space-vs-lifetime.aspx&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10026151" width="1" height="1"&gt;</description></item><item><title>re: Hide and seek</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/06/14/hide-and-seek.aspx#10025653</link><pubDate>Wed, 16 Jun 2010 08:45:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10025653</guid><dc:creator>Joren</dc:creator><description>&lt;p&gt;If hiding only happens within the scope of a member (which Main is outside of), then if D.X were public, why does B.X appear to be hidden in Main? Is it only because of the betterness algorithm?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10025653" width="1" height="1"&gt;</description></item><item><title>re: Hide and seek</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/06/14/hide-and-seek.aspx#10025548</link><pubDate>Wed, 16 Jun 2010 02:24:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10025548</guid><dc:creator>oReally</dc:creator><description>&lt;p&gt;You cant really hide a method, if someone really wants to call the &amp;quot;hidden&amp;quot; method they will always be able to.&lt;/p&gt;
&lt;p&gt;Anyhow, IMHO if some class in you&amp;#39;re inheritance chain needs to hide public inherited members then probably something is wrong with your class hierarchy to begin with. You should think more in a &amp;quot;has a&amp;quot; relationship than a &amp;quot;is a&amp;quot; type relationship in most of those cases.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10025548" width="1" height="1"&gt;</description></item><item><title>re: Hide and seek</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/06/14/hide-and-seek.aspx#10025513</link><pubDate>Wed, 16 Jun 2010 00:26:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10025513</guid><dc:creator>David</dc:creator><description>&lt;p&gt;So what is the recommended way for a subclass to hide a function from the base class? A public implementation that throws an exception when called?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10025513" width="1" height="1"&gt;</description></item><item><title>re: Hide and seek</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/06/14/hide-and-seek.aspx#10025243</link><pubDate>Tue, 15 Jun 2010 16:14:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10025243</guid><dc:creator>oReally</dc:creator><description>&lt;p&gt;Good to learn something new. I didn&amp;#39;t realize freeborn&amp;#39;s question had a catch to it, as D.X obviously does hide B.X in that case. I get lost with some of these terms in english (not my native language). Do you have any blog where you explain what we are exactly referring to when we talk about scope, domains, declaration spaces, etc?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10025243" width="1" height="1"&gt;</description></item><item><title>re: Hide and seek</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/06/14/hide-and-seek.aspx#10024654</link><pubDate>Mon, 14 Jun 2010 17:56:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10024654</guid><dc:creator>oReally</dc:creator><description>&lt;p&gt;Yes it does. The new member is public so any call to it is within it&amp;#39;s scope.&lt;/p&gt;
&lt;div class="yellowbox"&gt;
&lt;p&gt;You are confusing scope with accessibility domain. The scope of an entity is the region of program text in which it is legal to refer to the entity by an unqualified name; a public field of a class is in scope only inside the class. Anywhere else you have to qualify its name to access it. The accessibility domain of a public member of a public class is everywhere; the accessibility domain is the region of program text where it is legal to refer to the entity by qualified or unqualified name.&lt;/p&gt;
&lt;p&gt;The problem was that I was not calling out the specific part of the spec that dealt with the relationship between member lookup and hidden members. I&amp;#39;ve clarified the text.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;- Eric&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10024654" width="1" height="1"&gt;</description></item><item><title>re: Hide and seek</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/06/14/hide-and-seek.aspx#10024634</link><pubDate>Mon, 14 Jun 2010 17:45:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10024634</guid><dc:creator>freeborn</dc:creator><description>&lt;p&gt;The specification says &amp;quot;A declaration of a new member hides an inherited member only within the scope of the new member.&amp;quot;, but says nothing about the lower accessibility.&lt;/p&gt;
&lt;p&gt;if we replace protected to public &lt;/p&gt;
&lt;p&gt;&amp;nbsp;class D : B { new public int X() } &amp;nbsp;&lt;/p&gt;
&lt;p&gt;D.X won&amp;#39;t hide &amp;nbsp;B.X in the main method? &lt;/p&gt;
&lt;div class="yellowbox"&gt;
&lt;p&gt;Excellent question. The way I originally wrote this article implied what you stated, which of course is incorrect. I&amp;#39;ve clarified the text. The relevant portion of the spec is in the member lookup section. - Eric&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10024634" width="1" height="1"&gt;</description></item></channel></rss>