<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mingbo &#187; 继承</title>
	<atom:link href="http://shao.mingbo.de/tag/%e7%bb%a7%e6%89%bf/feed/" rel="self" type="application/rss+xml" />
	<link>http://shao.mingbo.de</link>
	<description>包括教育技术，编程，互联网等方面的文章及随想。</description>
	<lastBuildDate>Thu, 26 Aug 2010 02:57:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>cSharp继承的学习笔记-PartTwo</title>
		<link>http://shao.mingbo.de/2009/11/28/inheritance-notes-of-csharp-part-two/</link>
		<comments>http://shao.mingbo.de/2009/11/28/inheritance-notes-of-csharp-part-two/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 07:06:56 +0000</pubDate>
		<dc:creator>邵 明博</dc:creator>
				<category><![CDATA[.NET 编程]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[myNote]]></category>
		<category><![CDATA[密封]]></category>
		<category><![CDATA[接口]]></category>
		<category><![CDATA[继承]]></category>

		<guid isPermaLink="false">http://shao.mingbo.de/?p=297</guid>
		<description><![CDATA[本文承接于《cSharp继承的学习笔记-PartOne》，主要谈谈继承这一章节关于密封和接口中我认为重要的知识。 密封：对于类来说，不能继承该类；对方法来说，不能重写。 在《对象和类》中提到，结构本身是不支持类型继承，那是因为结构是隐式密封的。 在方法中或属性中使用sealed 关键字时，必须与override连用。 接口：只能包含方法，属性，索引和事件；不能包含构造函数（其本身，不允许实例化，何谈构造？），不允许运算符重载（引起.net 的其他语言不兼容的问题，如：VB） 接口可以理解为一种契约，当你和别人签订了契约，就有责任实现其中的每个方法，如若有一个方法没实现，那请不要签定该契约。当契约生效时，其他的c#代码便可通过接口知道该方法支持的特性。 相关文章2009年11月29日 -- cSharp数组的学习笔记2009年11月28日 -- cSharp继承的学习笔记-PartOne2009年12月22日 -- cSharp中BackgroundWorker的用法2009年12月21日 -- cSharp中同步类的设计2009年12月20日 -- cSharp中给线程传递参数]]></description>
			<content:encoded><![CDATA[<p>本文承接于《<a href="http://shao.mingbo.de/2009/11/28/inheritance-notes-of-csharp-part-one/" target="_blank">cSharp继承的学习笔记-PartOne</a>》，主要谈谈继承这一章节关于<strong>密封和接口</strong>中我认为重要的知识。</p>
<p><strong>密封</strong>：对于类来说，不能继承该类；对方法来说，不能重写。</p>
<ul>
<li>在《<a href="http://shao.mingbo.de/2009/11/26/object-and-class-in-csharp/" target="_blank">对象和类</a>》中提到，结构本身是不支持类型继承，那是因为结构是隐式密封的。</li>
<li>在方法中或属性中使用sealed 关键字时，必须与override连用。</li>
</ul>
<p><strong>接口</strong>：只能包含方法，属性，索引和事件；不能包含构造函数（其本身，不允许实例化，何谈构造？），不允许运算符重载（引起.net 的其他语言不兼容的问题，如：VB）</p>
<p><strong>接口</strong>可以理解为一种契约，当你和别人签订了契约，<span style="color: #ff0000;">就有责任实现其中的每个方法</span>，如若有一个方法没实现，那请不要签定该契约。当契约生效时，其他的c#代码便可通过接口知道该方法支持的特性。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年11月29日 -- <a href="http://shao.mingbo.de/2009/11/29/arrays-notes-in-csharp/" title="cSharp数组的学习笔记">cSharp数组的学习笔记</a></li><li>2009年11月28日 -- <a href="http://shao.mingbo.de/2009/11/28/inheritance-notes-of-csharp-part-one/" title="cSharp继承的学习笔记-PartOne">cSharp继承的学习笔记-PartOne</a></li><li>2009年12月22日 -- <a href="http://shao.mingbo.de/2009/12/22/how-to-use-backgroundworker-in-csharp/" title="cSharp中BackgroundWorker的用法">cSharp中BackgroundWorker的用法</a></li><li>2009年12月21日 -- <a href="http://shao.mingbo.de/2009/12/21/synchronize-class-design-in-csharp/" title="cSharp中同步类的设计">cSharp中同步类的设计</a></li><li>2009年12月20日 -- <a href="http://shao.mingbo.de/2009/12/20/paralize-thread-in-charp/" title="cSharp中给线程传递参数">cSharp中给线程传递参数</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://shao.mingbo.de/2009/11/28/inheritance-notes-of-csharp-part-two/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>cSharp继承的学习笔记-PartOne</title>
		<link>http://shao.mingbo.de/2009/11/28/inheritance-notes-of-csharp-part-one/</link>
		<comments>http://shao.mingbo.de/2009/11/28/inheritance-notes-of-csharp-part-one/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 16:35:28 +0000</pubDate>
		<dc:creator>邵 明博</dc:creator>
				<category><![CDATA[.NET 编程]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[myNote]]></category>
		<category><![CDATA[继承]]></category>
		<category><![CDATA[隐藏函数]]></category>

		<guid isPermaLink="false">http://shao.mingbo.de/?p=289</guid>
		<description><![CDATA[在昨天的笔记中提到“结构本身不支持继承”，实际上有些武断。结构不能建立类型层次，但结构可以实现接口。 c# 的隐藏方法，这一块一直都觉得挺晦涩难懂。实际上，是没有理解出，它和虚函数之间的关系。下面以一个例子说明： static void Main(string[] args) { testClass t = new testClass2(); t.myMethod(); t.my(); } class testClass { public void myMethod() { Console.WriteLine("In base method"); } public virtual void my() { Console.WriteLine("Virtual in base"); } } class testClass2 : testClass { public new void myMethod() { Console.WriteLine("In child method"); } public override void my() [...]]]></description>
			<content:encoded><![CDATA[<p>在昨天的笔记中提到“结构本身不支持继承”，实际上有些武断。结构不能建立类型层次，但结构可以实现接口。</p>
<p><strong>c# 的隐藏方法</strong>，这一块一直都觉得挺晦涩难懂。实际上，是没有理解出，它和虚函数之间的关系。下面以一个例子说明：</p>
<pre name="code" class="c-sharp">        static void Main(string[] args)
        {

            testClass t = new testClass2();
            t.myMethod();
            t.my();
        }

        class testClass
        {
            public void myMethod()
            {
                Console.WriteLine("In base method");
            }

            public virtual void my()
            {
                Console.WriteLine("Virtual in base");
            }

        }

        class testClass2 : testClass
        {
            public new void myMethod()
            {
                Console.WriteLine("In child method");
            }

            public override void my()
            {
                Console.WriteLine("override in derived");
            }
        }</pre>
<ul>
<li>有没有new 这个显式的声明隐藏方法的形式，不是必须的。如果没有，则编译器会还会警告你，它会默认的按照隐藏基类的方法执行。</li>
<li>从编译结果看来，隐藏函数和虚函数的区别是，override 虚函数后，用基类引用子类的实例并调用该函数，会显示其多态性。但，隐藏函数则会直接显示其基类中的相关函数。</li>
</ul>
<p>&#8212;&#8212;&#8212;&#8212;以下与笔记无关&#8212;&#8212;&#8212;&#8212;</p>
<p>最近这两天的效率实在是低。昨天是相当于一整天只更新了一篇关于《<a href="http://shao.mingbo.de/2009/11/26/object-and-class-in-csharp/" target="_blank">对象和类</a>》的日志，而今天只看了<strong>继承</strong>这一章的1/6 的内容。持续的低迷，精神状态是一方面的原因——午睡的时间给耽误了，加上早先的几天的熬夜，显得这几天看书效率低了好几个档次。另外，今天下午还是铁着心，跑出去买了一个<a href="http://www.pny.com.cn/news_1.asp?ID=110" target="_blank">PNY 的浪漫紫罗双子盘</a>+<a href="http://www.onda.cn/pro/product/product.jsp?Id=14412&amp;PT=2" target="_blank">一个昂达的方块糖P3 </a>，很心疼的说。提起U盘，那真是一头包的，月头才买不久的Sandisk 就神不知鬼不觉的不见了；提起这次买的P3，让我想起04 年那会，昂达刚出第一款<a href="http://www.onda.cn/pro/product/product.jsp?Id=4305&amp;PT=2" target="_blank">vx505</a> 时，我就买了。</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年11月28日 -- <a href="http://shao.mingbo.de/2009/11/28/inheritance-notes-of-csharp-part-two/" title="cSharp继承的学习笔记-PartTwo">cSharp继承的学习笔记-PartTwo</a></li><li>2009年12月22日 -- <a href="http://shao.mingbo.de/2009/12/22/how-to-use-backgroundworker-in-csharp/" title="cSharp中BackgroundWorker的用法">cSharp中BackgroundWorker的用法</a></li><li>2009年12月21日 -- <a href="http://shao.mingbo.de/2009/12/21/synchronize-class-design-in-csharp/" title="cSharp中同步类的设计">cSharp中同步类的设计</a></li><li>2009年12月20日 -- <a href="http://shao.mingbo.de/2009/12/20/paralize-thread-in-charp/" title="cSharp中给线程传递参数">cSharp中给线程传递参数</a></li><li>2009年12月19日 -- <a href="http://shao.mingbo.de/2009/12/19/asynchronous-delegate-in-csharp/" title="cSharp中异步委托的笔记">cSharp中异步委托的笔记</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://shao.mingbo.de/2009/11/28/inheritance-notes-of-csharp-part-one/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
