<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 关于C#一个基础问题的初步探查</title>
	<atom:link href="http://blog.axqd.net/2005/04/27/basic-question-of-c-sharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.axqd.net/2005/04/27/basic-question-of-c-sharp/</link>
	<description>by aXqd</description>
	<lastBuildDate>Mon, 19 Dec 2011 09:58:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: fgg</title>
		<link>http://blog.axqd.net/2005/04/27/basic-question-of-c-sharp/comment-page-1/#comment-157</link>
		<dc:creator>fgg</dc:creator>
		<pubDate>Fri, 25 Apr 2008 09:25:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.axqd.net/?p=384#comment-157</guid>
		<description>建议看看这篇文章对你会有帮助的
http://www.150it.cn/bianchengwendang/Csap/1725591711559.html</description>
		<content:encoded><![CDATA[<p>建议看看这篇文章对你会有帮助的<br />
<a href="http://www.150it.cn/bianchengwendang/Csap/1725591711559.html" rel="nofollow">http://www.150it.cn/bianchengwendang/Csap/1725591711559.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: axqd</title>
		<link>http://blog.axqd.net/2005/04/27/basic-question-of-c-sharp/comment-page-1/#comment-156</link>
		<dc:creator>axqd</dc:creator>
		<pubDate>Thu, 12 May 2005 09:25:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.axqd.net/?p=384#comment-156</guid>
		<description>至于那几个virtual其实是我自己说的有点搅拉，不过确实IL中的某些virtual不一定算我们通常所谓的virtual...</description>
		<content:encoded><![CDATA[<p>至于那几个virtual其实是我自己说的有点搅拉，不过确实IL中的某些virtual不一定算我们通常所谓的virtual&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: axqd</title>
		<link>http://blog.axqd.net/2005/04/27/basic-question-of-c-sharp/comment-page-1/#comment-155</link>
		<dc:creator>axqd</dc:creator>
		<pubDate>Thu, 12 May 2005 09:25:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.axqd.net/?p=384#comment-155</guid>
		<description>呵呵，nannan分析真是深入阿，看来确实不能直接把C#里的interface照C++里面理解....</description>
		<content:encoded><![CDATA[<p>呵呵，nannan分析真是深入阿，看来确实不能直接把C#里的interface照C++里面理解&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anan</title>
		<link>http://blog.axqd.net/2005/04/27/basic-question-of-c-sharp/comment-page-1/#comment-154</link>
		<dc:creator>anan</dc:creator>
		<pubDate>Fri, 06 May 2005 09:25:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.axqd.net/?p=384#comment-154</guid>
		<description>这个……

今天才仔细看了下，我没有看IL，不过我的理解是这样的：

所谓的接口，在C++和C#里是不一样的，在C++里只是一个抽象的概念，而在C#里有一个专门表示接口的类型interface，这在C++里是没有的。
C++里是用抽象类和纯虚函数来起到接口的作用的，而纯虚函数自然是virtual的。
而C#不同，是用一个特有的类型interface来表示接口的，并不是用class。所以我想内部的实现肯定不同于C++。继承了某个 interface的class只是被强制要求必须实现某个function，而这个function并没有被加入vtable（我不知道CLI里是怎么实现多态的，姑且这样说吧）。这个看法从C#并不支持多重继承，却支持实现多个接口这点也可以得到印证。
所以，在C#里，“我们的误解来自一个假设：Control::Paint()被自动视为vitrual”，这确实是一个误解，如果你不显示的将Control.Paint()声明为virtual的话，其子类TextBox类是不能用关键字override来修饰Paint()的。

另外，如果没有用new关键字的话，默认会隐藏其父类的同名函数，编译器会给出警告，这点确实是很明确的。
---------------------------------------------
就本例来说，如果环境是C#，并且Control.Paint()并没有被显式的声明为virtual的话，TextBox.Paint()不能被override修饰，Paint()只是一个普通函数，不会出现多态的行为。所以it的类型是IControl,实际被调用的函数也就是直接实现 IControl接口的类Control里的Control.Paint()。
如果用virtual修饰Control.Paint()，而没有用override修饰TextBox.Paint()的话，TextBox.Paint()默认行为等同于加上new关键字，隐藏父类方法，但并不会参与多态行为，it.Paint()能找到的最合适的匹配只能是Control.Paint()。
如果用virtual修饰了Control.Paint()，也用override修饰了TextBox.Paint()了的话，就是很正常的多态行为了，it.Paint()会被匹配到it的实际类型TextBox实现了的虚函数TextBox.Paint()。</description>
		<content:encoded><![CDATA[<p>这个……</p>
<p>今天才仔细看了下，我没有看IL，不过我的理解是这样的：</p>
<p>所谓的接口，在C++和C#里是不一样的，在C++里只是一个抽象的概念，而在C#里有一个专门表示接口的类型interface，这在C++里是没有的。<br />
C++里是用抽象类和纯虚函数来起到接口的作用的，而纯虚函数自然是virtual的。<br />
而C#不同，是用一个特有的类型interface来表示接口的，并不是用class。所以我想内部的实现肯定不同于C++。继承了某个 interface的class只是被强制要求必须实现某个function，而这个function并没有被加入vtable（我不知道CLI里是怎么实现多态的，姑且这样说吧）。这个看法从C#并不支持多重继承，却支持实现多个接口这点也可以得到印证。<br />
所以，在C#里，“我们的误解来自一个假设：Control::Paint()被自动视为vitrual”，这确实是一个误解，如果你不显示的将Control.Paint()声明为virtual的话，其子类TextBox类是不能用关键字override来修饰Paint()的。</p>
<p>另外，如果没有用new关键字的话，默认会隐藏其父类的同名函数，编译器会给出警告，这点确实是很明确的。<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
就本例来说，如果环境是C#，并且Control.Paint()并没有被显式的声明为virtual的话，TextBox.Paint()不能被override修饰，Paint()只是一个普通函数，不会出现多态的行为。所以it的类型是IControl,实际被调用的函数也就是直接实现 IControl接口的类Control里的Control.Paint()。<br />
如果用virtual修饰Control.Paint()，而没有用override修饰TextBox.Paint()的话，TextBox.Paint()默认行为等同于加上new关键字，隐藏父类方法，但并不会参与多态行为，it.Paint()能找到的最合适的匹配只能是Control.Paint()。<br />
如果用virtual修饰了Control.Paint()，也用override修饰了TextBox.Paint()了的话，就是很正常的多态行为了，it.Paint()会被匹配到it的实际类型TextBox实现了的虚函数TextBox.Paint()。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: axqd</title>
		<link>http://blog.axqd.net/2005/04/27/basic-question-of-c-sharp/comment-page-1/#comment-153</link>
		<dc:creator>axqd</dc:creator>
		<pubDate>Wed, 27 Apr 2005 09:24:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.axqd.net/?p=384#comment-153</guid>
		<description>&lt;C# Primer&gt;....</description>
		<content:encoded><![CDATA[<p><c # Primer>&#8230;.</c></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 深蓝</title>
		<link>http://blog.axqd.net/2005/04/27/basic-question-of-c-sharp/comment-page-1/#comment-152</link>
		<dc:creator>深蓝</dc:creator>
		<pubDate>Wed, 27 Apr 2005 09:24:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.axqd.net/?p=384#comment-152</guid>
		<description>研究的那么深奥哦！佩服，佩服！</description>
		<content:encoded><![CDATA[<p>研究的那么深奥哦！佩服，佩服！</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 卷毛</title>
		<link>http://blog.axqd.net/2005/04/27/basic-question-of-c-sharp/comment-page-1/#comment-151</link>
		<dc:creator>卷毛</dc:creator>
		<pubDate>Wed, 27 Apr 2005 09:24:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.axqd.net/?p=384#comment-151</guid>
		<description>CLI隐藏了很多东西,你这种程度的初学者有能力和自觉看IL是很好的选择</description>
		<content:encoded><![CDATA[<p>CLI隐藏了很多东西,你这种程度的初学者有能力和自觉看IL是很好的选择</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zengxi</title>
		<link>http://blog.axqd.net/2005/04/27/basic-question-of-c-sharp/comment-page-1/#comment-150</link>
		<dc:creator>zengxi</dc:creator>
		<pubDate>Wed, 27 Apr 2005 09:24:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.axqd.net/?p=384#comment-150</guid>
		<description>如果你看的是inside c＃的话， 由于那本书是基于。net beta版的，所以会和你实际测试有所出入</description>
		<content:encoded><![CDATA[<p>如果你看的是inside c＃的话， 由于那本书是基于。net beta版的，所以会和你实际测试有所出入</p>
]]></content:encoded>
	</item>
</channel>
</rss>

