<?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>An Inheritance Puzzle, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/07/27/an-inheritance-puzzle-part-one.aspx</link><description>Once more I have returned from my ancestral homeland, after some weeks of sun, rain, storms, wind, calm, friends and family. I could certainly use another few weeks, but it is good to be back too. Well, enough chit-chat; back to programming language design</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>C#小测试（二）：嵌套子类带来的困惑</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/07/27/an-inheritance-puzzle-part-one.aspx#8826469</link><pubDate>Mon, 04 Aug 2008 06:53:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8826469</guid><dc:creator>Anders Cui</dc:creator><description>&lt;p&gt;如果我们的代码中同时出现泛型、继承、嵌套类这三种语言元素，那么在根据名称解析类型的时候可能就会有歧义了。本文中的问题及其结论是非常有意思的，其分析过程也非常的绕，大家一起来讨论下吧:)&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8826469" width="1" height="1"&gt;</description></item><item><title>C#小测试（二）：嵌套子类带来的困惑</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/07/27/an-inheritance-puzzle-part-one.aspx#8816048</link><pubDate>Sun, 03 Aug 2008 14:25:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8816048</guid><dc:creator>Anders Cui</dc:creator><description>&lt;p&gt;如果我们的代码中同时出现泛型、继承、嵌套类这三种语言元素，那么在根据名称解析类型的时候可能就会有歧义了。本文中的问题及其结论是非常有意思的，其分析过程也非常的绕，大家一起来讨论下吧:)&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8816048" width="1" height="1"&gt;</description></item><item><title>re: An Inheritance Puzzle, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/07/27/an-inheritance-puzzle-part-one.aspx#5173792</link><pubDate>Fri, 28 Sep 2007 00:15:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5173792</guid><dc:creator>Gautam</dc:creator><description>&lt;p&gt;Hi Eric,&lt;/p&gt;
&lt;p&gt;If we modify the code like this ..&lt;/p&gt;
&lt;p&gt;public class A&amp;lt;T&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public void N()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(typeof(T).ToString());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public class B : A&amp;lt;int&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public void M()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(typeof(T).ToString());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public class C : B&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;static void Main()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&amp;lt;string&amp;gt;.B b = new A&amp;lt;string&amp;gt;.B(); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b.M();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b.N();&lt;/p&gt;
&lt;p&gt;Here, b.M() shows String but b.N() shows Int32. &amp;nbsp;I am confused how could it happen..... &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5173792" width="1" height="1"&gt;</description></item><item><title>re: An Inheritance Puzzle, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/07/27/an-inheritance-puzzle-part-one.aspx#5173553</link><pubDate>Thu, 27 Sep 2007 23:50:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5173553</guid><dc:creator>Gautam</dc:creator><description>&lt;p&gt;Hi Eric, I have a confusion, you mentioned that ** the question hinges solely upon what &amp;quot;B&amp;quot; means in &amp;quot;class C : B&amp;quot;, and in this case it means A&amp;lt;int&amp;gt;.B. ** &lt;/p&gt;
&lt;p&gt;So, if you consider the following code &lt;/p&gt;
&lt;p&gt;A&amp;lt;string&amp;gt;.B b = new A&amp;lt;string&amp;gt;.B(); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;b.M();&lt;/p&gt;
&lt;p&gt;Why in this case b.M() prints String not INT32 , here also &amp;quot;B&amp;quot; should be considered as A&amp;lt;int&amp;gt;.B ... what's your comment ....&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5173553" width="1" height="1"&gt;</description></item><item><title>An Inheritance Puzzle, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/07/27/an-inheritance-puzzle-part-one.aspx#4795683</link><pubDate>Fri, 07 Sep 2007 01:26:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4795683</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description>&lt;p&gt;Today, the answer to Friday's puzzle . It prints &amp;quot;Int32&amp;quot;. But why? Some readers hypothesized that M would&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4795683" width="1" height="1"&gt;</description></item><item><title>re: An Inheritance Puzzle, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/07/27/an-inheritance-puzzle-part-one.aspx#4102380</link><pubDate>Sat, 28 Jul 2007 18:13:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4102380</guid><dc:creator>Eric Lippert</dc:creator><description>&lt;p&gt;Steve:&lt;/p&gt;
&lt;p&gt;Excellent example! &amp;nbsp;Why is it that this DOESN'T reproduce the odd behaviour? The germane difference between the two is that in your example, A&amp;lt;T&amp;gt; does not contain anything called B.&lt;/p&gt;
&lt;p&gt;When I post what is really happening on Monday it'll be clear why this does what it does.&lt;/p&gt;
&lt;p&gt;You need the &amp;quot;new&amp;quot; because your method M shadows the in-scope type variable M from A&amp;lt;M&amp;gt;. &amp;nbsp;We try to make it either illegal to shadow like this, or make you put the keyword &amp;quot;new&amp;quot; on one of them as a big waving red flag that says &amp;quot;there is a name ambiguity involving this method, so keep that in mind when you are reading this code&amp;quot;.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4102380" width="1" height="1"&gt;</description></item><item><title>re: An Inheritance Puzzle, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/07/27/an-inheritance-puzzle-part-one.aspx#4101397</link><pubDate>Sat, 28 Jul 2007 16:45:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4101397</guid><dc:creator>Steve</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;public class A&amp;lt;M&amp;gt; {&lt;/p&gt;
&lt;p&gt;	public class X&amp;lt;T&amp;gt; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public class B : A&amp;lt;int&amp;gt; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public new void M() {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.Console.WriteLine(typeof(T).ToString());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.Console.WriteLine(typeof(M).ToString());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public class C : B { }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;... &lt;/p&gt;
&lt;p&gt;A&amp;lt;string&amp;gt;.X&amp;lt;double&amp;gt;.B.C c = new A&amp;lt;string&amp;gt;.X&amp;lt;double&amp;gt;.B.C();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c.M();&lt;/p&gt;
&lt;p&gt;Prints string and double. &lt;/p&gt;
&lt;p&gt;And why do I need the new keyword in M here?&lt;/p&gt;
&lt;p&gt;Your postings are way shorter than Chris Brumme's when he was still posting, but I am finding myself equally confused after reading them (I love that). So I guess you can consider yourself much more efficient:-)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4101397" width="1" height="1"&gt;</description></item><item><title>re: An Inheritance Puzzle, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/07/27/an-inheritance-puzzle-part-one.aspx#4098644</link><pubDate>Sat, 28 Jul 2007 13:13:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4098644</guid><dc:creator>Andrew Ducker</dc:creator><description>&lt;p&gt;Took me a few minutes to grasp this one. &amp;nbsp;The &amp;lt;T&amp;gt; is clearly referring to the containing class. &amp;nbsp;Which means that b.M() shows a string. But the container class for c is b - which is A&amp;lt;Int&amp;gt;.&lt;/p&gt;
&lt;p&gt;So yes, that makes sense - just took a moment to get there.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4098644" width="1" height="1"&gt;</description></item><item><title>re: An Inheritance Puzzle, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/07/27/an-inheritance-puzzle-part-one.aspx#4093934</link><pubDate>Sat, 28 Jul 2007 07:45:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4093934</guid><dc:creator>WaterBreath</dc:creator><description>&lt;p&gt;Sorry, I prefer to err on the side of politeness...&lt;/p&gt;
&lt;p&gt;As far as B inheriting T.... &amp;nbsp;I was trying to infer the inner workings here, to explain why in the world the example would yield int instead of string. &amp;nbsp;Some sort of weird inheritance of T was the only way I could figure that this would happen.&lt;/p&gt;
&lt;p&gt;Obviously there's some assumption I'm making that is wrong. &amp;nbsp;Either I don't understand the scoping rules, or I've got the order in which things happen all mixed up.&lt;/p&gt;
&lt;p&gt;I still think it _should_ output string. &amp;nbsp;=P&lt;/p&gt;
&lt;p&gt;Sigh.... &amp;nbsp;I'll wait for Monday.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4093934" width="1" height="1"&gt;</description></item><item><title>re: An Inheritance Puzzle, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2007/07/27/an-inheritance-puzzle-part-one.aspx#4092877</link><pubDate>Sat, 28 Jul 2007 07:11:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4092877</guid><dc:creator>Eric Lippert</dc:creator><description>&lt;p&gt;First off, Mr. Lippert is my father, dude.&lt;/p&gt;
&lt;p&gt;Second, I do not know what you mean by &amp;quot;the inheritance of the generic parameter T&amp;quot;. &amp;nbsp; T isn't inherited. &amp;nbsp;B doesn't have a T. &amp;nbsp;Only A&amp;lt;T&amp;gt; has a T.&lt;/p&gt;
&lt;p&gt;Hopefully my explanation on Monday will clear it all up.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4092877" width="1" height="1"&gt;</description></item></channel></rss>