﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-回来了</title><link>http://www.cnblogs.com/zhzkl/</link><description>.Net， 我回来了  
MSN: wangxiong#msn.com</description><language>zh-cn</language><lastBuildDate>Tue, 14 Oct 2008 11:32:58 GMT</lastBuildDate><pubDate>Tue, 14 Oct 2008 11:32:58 GMT</pubDate><ttl>60</ttl><item><title>[Programming IL]泛型, Generic Types</title><link>http://www.cnblogs.com/zhzkl/archive/2008/10/12/1309181.html</link><dc:creator>xwang</dc:creator><author>xwang</author><pubDate>Sun, 12 Oct 2008 07:23:00 GMT</pubDate><guid>http://www.cnblogs.com/zhzkl/archive/2008/10/12/1309181.html</guid><wfw:comment>http://www.cnblogs.com/zhzkl/comments/1309181.html</wfw:comment><comments>http://www.cnblogs.com/zhzkl/archive/2008/10/12/1309181.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/zhzkl/comments/commentRss/1309181.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/zhzkl/services/trackbacks/1309181.html</trackback:ping><description><![CDATA[摘要: 引言: 自从泛型那天诞生起，广大的面向对象程序员对于他的热爱普遍要高于其他数据结构. :). 然而各大面向对象对于他的支持却不太一样。在CPP中用的是静态编译，即在编译器决定泛型的类型，而.Net则是在运行时确定，他们有什么不一样呢? 和周围的同事谈起泛型，发现大伙对于这东西都是似懂非懂，觉得自己有必要作一次应用总结了. :( ， 由于范型内容较多，请看这里:  我们从C#总定义一段基本的范型代码&nbsp;&nbsp;<a href='http://www.cnblogs.com/zhzkl/archive/2008/10/12/1309181.html'>阅读全文</a><img src ="http://www.cnblogs.com/zhzkl/aggbug/1309181.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42984/" target="_blank">[新闻]Silverlight 2正式版SDK可以下载</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>Shared Source CLI 2.0 Internals Draft Released</title><link>http://www.cnblogs.com/zhzkl/archive/2008/10/10/1307798.html</link><dc:creator>xwang</dc:creator><author>xwang</author><pubDate>Fri, 10 Oct 2008 01:57:00 GMT</pubDate><guid>http://www.cnblogs.com/zhzkl/archive/2008/10/10/1307798.html</guid><wfw:comment>http://www.cnblogs.com/zhzkl/comments/1307798.html</wfw:comment><comments>http://www.cnblogs.com/zhzkl/archive/2008/10/10/1307798.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnblogs.com/zhzkl/comments/commentRss/1307798.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/zhzkl/services/trackbacks/1307798.html</trackback:ping><description><![CDATA[<p>Essential Shared Source CLI 的第二版的电子草稿版本出来了，想学习的朋友有福了，下面是地址</p> <p>查看: <a href="http://callvirt.net/blog/entry.aspx?entryid=b9a94d0c-761a-4d6b-bc2f-d6a5f8c1a4a7">http://callvirt.net/blog/entry.aspx?entryid=b9a94d0c-761a-4d6b-bc2f-d6a5f8c1a4a7</a></p> <p>书籍下载地址: <a href="http://callvirt.net/files/Shared%20Source%20CLI%202.0%20Internals%20DRAFT.pdf">Shared Source CLI 2.0 Internals DRAFT.pdf</a>.</p> <img src ="http://www.cnblogs.com/zhzkl/aggbug/1307798.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42983/" target="_blank">[新闻]Silverlight对Flash 微软打垮Adobe</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>Understanding Generic Type, 理解泛型</title><link>http://www.cnblogs.com/zhzkl/archive/2008/10/10/1307785.html</link><dc:creator>xwang</dc:creator><author>xwang</author><pubDate>Fri, 10 Oct 2008 01:45:00 GMT</pubDate><guid>http://www.cnblogs.com/zhzkl/archive/2008/10/10/1307785.html</guid><wfw:comment>http://www.cnblogs.com/zhzkl/comments/1307785.html</wfw:comment><comments>http://www.cnblogs.com/zhzkl/archive/2008/10/10/1307785.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/zhzkl/comments/commentRss/1307785.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/zhzkl/services/trackbacks/1307785.html</trackback:ping><description><![CDATA[摘要: 什么是泛型 所谓泛型，就是指类型可以为任意. 最常用的泛型当然是用于创建集合了. 1: List&lt;int&gt; list = new List&lt;int&gt;(); 2: list.Add(1);  为什么要用泛型?这个问题可以分为几个分支, 我们一个一个来思考泛型跟传统的集合类比较有什么优势a. 效率好,因为集合类(以ArrayList为例)对于所有对象的操作采用object作为对&nbsp;&nbsp;<a href='http://www.cnblogs.com/zhzkl/archive/2008/10/10/1307785.html'>阅读全文</a><img src ="http://www.cnblogs.com/zhzkl/aggbug/1307785.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42983/" target="_blank">[新闻]Silverlight对Flash 微软打垮Adobe</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>[Programming IL]虚方法，重载，抽象方法，覆盖 - Virtual Methods, Overload, Abstract, Override</title><link>http://www.cnblogs.com/zhzkl/archive/2008/09/21/1295109.html</link><dc:creator>xwang</dc:creator><author>xwang</author><pubDate>Sat, 20 Sep 2008 18:20:00 GMT</pubDate><guid>http://www.cnblogs.com/zhzkl/archive/2008/09/21/1295109.html</guid><wfw:comment>http://www.cnblogs.com/zhzkl/comments/1295109.html</wfw:comment><comments>http://www.cnblogs.com/zhzkl/archive/2008/09/21/1295109.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/zhzkl/comments/commentRss/1295109.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/zhzkl/services/trackbacks/1295109.html</trackback:ping><description><![CDATA[摘要: 引言 前面我们讲到了接口，类，流程控制，那面向对象的一些基本概念，重载，覆盖，抽象/虚方法这些概念在.Net中又是如何实现的呢? 概念 可能提了无数次了，然后还是要定义一下, 温故而知新嘛. :) 这些面向对象的基本元素都是和方法联系在一起。方法由方法头(Method Header)和方法体(Method Body)组成，方法头由 ( 修饰符，返回值，方法名，定义域修饰符(internal), 参&nbsp;&nbsp;<a href='http://www.cnblogs.com/zhzkl/archive/2008/09/21/1295109.html'>阅读全文</a><img src ="http://www.cnblogs.com/zhzkl/aggbug/1295109.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42981/" target="_blank">[新闻]IBM扩大研究规模 在上海成立研究院</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>[Programming IL]创建一个接口，How To Declare A Interface</title><link>http://www.cnblogs.com/zhzkl/archive/2008/09/19/1293782.html</link><dc:creator>xwang</dc:creator><author>xwang</author><pubDate>Thu, 18 Sep 2008 16:09:00 GMT</pubDate><guid>http://www.cnblogs.com/zhzkl/archive/2008/09/19/1293782.html</guid><wfw:comment>http://www.cnblogs.com/zhzkl/comments/1293782.html</wfw:comment><comments>http://www.cnblogs.com/zhzkl/archive/2008/09/19/1293782.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/zhzkl/comments/commentRss/1293782.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/zhzkl/services/trackbacks/1293782.html</trackback:ping><description><![CDATA[<h4>引言:</h4> <p>大家都知道接口是定义了一组契约，但是你知道接口的存在形式吗? 你想更深一步了解接口吗? Follow me. :)</p> <h3>概念:</h3> <blockquote> <p>Interfaces define a contract that other types can implement. Interfaces can have <br>static fields and methods, but they shall not have instance fields or methods.&nbsp; Interfaces can define virtual methods.&nbsp; </p> <p>- From Common Language Infrastructure (CLI) Partition II</p>"A named group of methods, locations, and other contracts that shall be imple<br>mented by any object type that supports the interface contract of the same name"&nbsp;&nbsp;&nbsp; - From ECMA / ISO  <p>接口定义了一个契约，并由继承他的类来实现。</p> <ol> <li>可以有<strong>静态的字段和方法</strong>，但是实际上他们不应该有（只是一种能力，但是不应该使用）。  <li>定义的实例方法都是Virtual的.  <li>不存在内存布局，因为他没有自己的实现. 从而也不知道那个方法占用多少个字节.等等 (有待继续深究)</li></ol></blockquote> <h3>Q &amp; A - 从问题展开探索</h3> <h4>Q: 是否继承接口的类都必须有接口的实现呢？</h4> <p>A: 抽象类除外. (Abstract Class Excluded)</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> ITest</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>         <span style="color: #0000ff">void</span> Run();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">abstract</span> <span style="color: #0000ff">class</span> MyTest : ITest</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">abstract</span> <span style="color: #0000ff">void</span> Run();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>         </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>     }</pre></div></div>
<p>更进一步，为什么Abstract的方法也可以呢 ？</p>
<p>换个角度如果不是Abstract的方法自然是可以的，但是为什么Abstract也行呢?</p>
<p>区别在于一个有具体的实现，而另一个无。然而对于最后生成的元数据结构来说，对于每个方法都存在自己的签名，实例方法如此，Abstract的方法也如是，而对于Abstract的实现类来说必定存在Abstract方法的具体实现，于是乎，这样的实现也是可以并且也是有道理的，权当一种.Net面向对象的一种特征好了. :). BTW: 不知道其他的面向对象语言怎样约定的？</p>
<p>举个例子:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> ITest test = <span style="color: #0000ff">new</span> DerivedClass(); <span style="color: #008000">// Derived lass --&gt; Abstract Class --&gt; ITest</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> test.Call();</pre></div></div>
<table cellspacing="0" cellpadding="4" width="660" border="0">
<tbody>
<tr>
<td valign="top" width="173">方法\类型&nbsp; 执行顺序 -&gt;</td>
<td valign="top" width="117">Interface</td>
<td valign="top" width="186">Abstract class </td>
<td valign="top" width="183">Derived Class</td></tr>
<tr>
<td valign="top" width="173">实例::方法</td>
<td valign="top" width="117">ITest:: Call()</td>
<td valign="top" width="190">AbstractInstance::Call()</td>
<td valign="top" width="186">DerivedInstance::Call()</td></tr></tbody></table>
<p>依此类推, 这样也是对的</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> MyVirtualTest: ITest</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> Run(){}</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     }</pre></div></div>
<h4>Q: 定义上写可以定义静态的字段和方法? 那么为什么编译会报错</h4>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> ITest</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>         <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Run();</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     }</pre></div></div>
<p>错误: The modifier 'static' is not valid for this item</p>
<p>这样也不行</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> ITest</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">static</span> <span style="color: #0000ff">int</span> Count = 5;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> }</pre></div></div>
<p>错误: Interfaces cannot contain fields</p>
<p>这样的例子是在C#中运行的，我们用IL试一下</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> .<span style="color: #0000ff">class</span> <span style="color: #0000ff">interface</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">abstract</span> auto ansi Roger.Testing.ITest</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>   .method <span style="color: #0000ff">public</span> hidebysig newslot <span style="color: #0000ff">abstract</span> <span style="color: #0000ff">virtual</span> </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>           instance <span style="color: #0000ff">void</span>  Run() cil managed</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>   {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>   } <span style="color: #008000">// end of method ITest::Run</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>   .field <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> int32 id</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span> } <span style="color: #008000">// end of class Roger.Testing.ITest</span></pre></div></div>
<p>编译成功, 我们反编译一下:</p>
<p><a href="http://www.cnblogs.com/images/cnblogs_com/zhzkl/WindowsLiveWriter/ProgrammingILHowToDeclareAInterface_13785/image_4.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="144" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/zhzkl/WindowsLiveWriter/ProgrammingILHowToDeclareAInterface_13785/image_thumb_1.png" width="491" border="0"></a> </p>
<p>那定义一个静态方法呢?</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> .<span style="color: #0000ff">class</span> <span style="color: #0000ff">interface</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">abstract</span> auto ansi Roger.Testing.ITest</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>   .method <span style="color: #0000ff">public</span> hidebysig newslot <span style="color: #0000ff">abstract</span> <span style="color: #0000ff">virtual</span> </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>           instance <span style="color: #0000ff">void</span>  Run() cil managed</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>   {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>   } <span style="color: #008000">// end of method ITest::Run</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>   .field <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> int32 id</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>   .method <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> MyStaticFun() cil managed</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>   {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>     ret</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>   }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span> } // end of <span style="color: #0000ff">class</span> Roger.Testing.ITest</pre></div></div>
<p>编译成功后继续反编译:</p>
<p><a href="http://www.cnblogs.com/images/cnblogs_com/zhzkl/WindowsLiveWriter/ProgrammingILHowToDeclareAInterface_13785/image_6.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="320" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/zhzkl/WindowsLiveWriter/ProgrammingILHowToDeclareAInterface_13785/image_thumb_2.png" width="453" border="0"></a></p>
<p>题外话：我们都知道Java里接口是可以定义静态变量，我想这是不是.Net设计时的一种考量，在CLI基础上内建了支持，而后根据语言特性定制，而C#不支持接口定义静态变量与方法. :) </p>
<p>再扯偏一点, 既然接口可以定义静态变量和方法，这些方法和变量需要在实现这个接口的类中再实现一次吗?</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> .<span style="color: #0000ff">class</span> <span style="color: #0000ff">public</span> auto MyClass extends [mscorlib]::System.Object</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>                implements Roger.Testing.ITest</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     <span style="color: #008000">// Implement the override methods</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span> }</pre></div></div>
<p>答案: 不需要</p>
<p>原因: static变量为这个interface的l类型拥有，不需要继续实现，此例即为: ITest.id</p> <img src ="http://www.cnblogs.com/zhzkl/aggbug/1293782.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42980/" target="_blank">[新闻]eWeek评Google八大“20%项目”</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>[Programming IL]创建一个类，How To Declare A Class</title><link>http://www.cnblogs.com/zhzkl/archive/2008/09/19/1293781.html</link><dc:creator>xwang</dc:creator><author>xwang</author><pubDate>Thu, 18 Sep 2008 16:08:00 GMT</pubDate><guid>http://www.cnblogs.com/zhzkl/archive/2008/09/19/1293781.html</guid><wfw:comment>http://www.cnblogs.com/zhzkl/comments/1293781.html</wfw:comment><comments>http://www.cnblogs.com/zhzkl/archive/2008/09/19/1293781.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/zhzkl/comments/commentRss/1293781.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/zhzkl/services/trackbacks/1293781.html</trackback:ping><description><![CDATA[摘要: 引言 在.Net平台中，面向对象是一个非常重要的概念，那么在IL是怎样对面向对象进行支持的呢? 让我们从创建一个类开始 例子 1: .assembly extern mscorlib {} 2: .assembly MyClass {} 3: .class public auto unicode XWang extends [mscorlib]System.Object 4: { 5: .meth&nbsp;&nbsp;<a href='http://www.cnblogs.com/zhzkl/archive/2008/09/19/1293781.html'>阅读全文</a><img src ="http://www.cnblogs.com/zhzkl/aggbug/1293781.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42980/" target="_blank">[新闻]eWeek评Google八大“20%项目”</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>[Programming IL] 从Hello World开始</title><link>http://www.cnblogs.com/zhzkl/archive/2008/09/12/1289631.html</link><dc:creator>xwang</dc:creator><author>xwang</author><pubDate>Fri, 12 Sep 2008 01:21:00 GMT</pubDate><guid>http://www.cnblogs.com/zhzkl/archive/2008/09/12/1289631.html</guid><wfw:comment>http://www.cnblogs.com/zhzkl/comments/1289631.html</wfw:comment><comments>http://www.cnblogs.com/zhzkl/archive/2008/09/12/1289631.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/zhzkl/comments/commentRss/1289631.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/zhzkl/services/trackbacks/1289631.html</trackback:ping><description><![CDATA[<p>&nbsp;</p> <h4>名词解释</h4> <p>IL = Intermediate Language, 在.Net的设计中成为CIL = Common Intermediate Language, 而因为CIL本身是通用的，而微软为他设计了一种实现，在微软平台上我们也可以称他为MSIL</p> <p><b>目标</b></p> <p>为.Net平台的底层设计提供一个具体实现，基本编程语言的特性，如流程控制，判断，算术计算，地址等等。还有面向对象的具体设计，类和类之间的关系，隐藏，继承，接口等等。更有一些对函数式语言的支持，了解IL不仅仅是对程序的深一步理解，更是对.Net Framework产生框架性认识的重要依据。个人认为 :)</p> <h4>基础知识</h4> <p>每一个.Net应用程序或者是程序集都实际上一个PE(Portable Execution)文件, 关于PE文件格式等等的详细说明将在后面讲述</p> <h4>实例 - 从HelloWrold开始</h4> <p>代码:</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244,244,244)"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: rgb(244,244,244); border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: rgb(96,96,96)">   1:</span> .assembly <span style="color: rgb(0,0,255)">extern</span> mscorlib {}</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: rgb(244,244,244); border-bottom-style: none"><span style="color: rgb(96,96,96)">   2:</span> .assembly hello {}</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: rgb(96,96,96)">   3:</span> .method <span style="color: rgb(0,0,255)">static</span> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">void</span> main() cil managed</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: rgb(244,244,244); border-bottom-style: none"><span style="color: rgb(96,96,96)">   4:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: rgb(96,96,96)">   5:</span>     .entrypoint</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: rgb(244,244,244); border-bottom-style: none"><span style="color: rgb(96,96,96)">   6:</span>     .maxstack 1</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: rgb(96,96,96)">   7:</span>     ldstr <span style="color: rgb(0,96,128)">"Hello world!"</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: rgb(244,244,244); border-bottom-style: none"><span style="color: rgb(96,96,96)">   8:</span>     call <span style="color: rgb(0,0,255)">void</span> [mscorlib]System.Console::WriteLine(<span style="color: rgb(0,0,255)">class</span> System.String)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: rgb(96,96,96)">   9:</span>     ret</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas,'Courier New',courier,monospace; border-right-style: none; border-left-style: none; background-color: rgb(244,244,244); border-bottom-style: none"><span style="color: rgb(96,96,96)">  10:</span> }</pre></div></div>
<p>1. mscorlib位于 %Windows%/Microsoft.NET/Framework/v2.0.50727 下，他是.Net程序和API交互的基础，包含了基础类库(BCL)的实现</p>
<p>2. 设置程序集名称为hello</p>
<p>3. ...</p>
<p>5. .entrypoint&nbsp; 入口点</p>
<p>6. 分配栈</p>
<p>7. 加载string</p>
<p>8. 调用方法</p>
<p>9. 返回</p>
<p>&nbsp;</p>
<p>了解IL很久了，最近探索下.Net设计等等东西， 开始看IL也有一段时间了，工作比较忙，反而搁置了，写这个东西也不是为了啥，只是督促自己一下.</p>
<p>参考书籍:</p>
<p>Expert.NET 2.0 IL Assembler</p>
<p>Common Language Infrastructure Partition II</p> <img src ="http://www.cnblogs.com/zhzkl/aggbug/1289631.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42979/" target="_blank">[新闻]微软终于发布Silverlight 2正式版</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>装饰者模式(Decorator pattern)</title><link>http://www.cnblogs.com/zhzkl/archive/2008/09/08/1287190.html</link><dc:creator>xwang</dc:creator><author>xwang</author><pubDate>Mon, 08 Sep 2008 15:49:00 GMT</pubDate><guid>http://www.cnblogs.com/zhzkl/archive/2008/09/08/1287190.html</guid><wfw:comment>http://www.cnblogs.com/zhzkl/comments/1287190.html</wfw:comment><comments>http://www.cnblogs.com/zhzkl/archive/2008/09/08/1287190.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/zhzkl/comments/commentRss/1287190.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/zhzkl/services/trackbacks/1287190.html</trackback:ping><description><![CDATA[<p>说起来惭愧，在某群解答别人问题时居然回答错误，羞煞我也。为此特地补习一下。 :(</p> <h3>装饰者模式</h3> <h4>作用:</h4> <p>动态给对象添加职责</p> <h4>典型案例:</h4> <p>在一般的留言本中(支持UBB)输入文本，按B设置为粗体，I为斜体，实际上就是给文本动态的加上了&lt;b&gt;文本&lt;/b&gt;，&lt;I&gt;等文字环绕&lt;/I&gt;，而后通过解释器进行替换于是就有了最终页面的效果。这样的思路是很简单的，然而对于面向对象的实现方式来说其实还是有点麻烦的. 鉴于关于文本的例子过多，我们这里举的例子采用Stream的简化版本</p> <h4>类图:</h4> <p><a href="http://www.cnblogs.com/images/cnblogs_com/zhzkl/WindowsLiveWriter/Decoratorpattern_14DEF/Decoator_4.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="297" alt="Decoator" src="http://www.cnblogs.com/images/cnblogs_com/zhzkl/WindowsLiveWriter/Decoratorpattern_14DEF/Decoator_thumb_1.png" width="660" border="0"></a> </p> <p>对于.Net Framework中存在N种流, FileStream, MemoryStream, BinaryStream, NullStream等等，无非这些Stream都是Stream的确定实例，而通过CryptoStream的子类来对各种流进行加密解密等等功能的操作，在我们的类图里使用SecurityStream和子类HashedStreamDecorator, SHAStreamDecorator等来表示</p> <p>关于实现的代码的方式则很简单，相信读者通过类图即可得到程序。实际BCL中的Stream会麻烦许多，会有很多的虚方法，Read, Seek,同步流，异步流等等，然而架构是一样的</p> <p>关于动态职责的添加还有很多实现，这里还有一种AOP的方法， :)</p> <p><a title="http://msdn.microsoft.com/en-us/magazine/cc163741.aspx" href="http://msdn.microsoft.com/en-us/magazine/cc163741.aspx">http://msdn.microsoft.com/en-us/magazine/cc163741.aspx</a></p> <p>关于AOP的简述:</p> <p><a title="http://msdn.microsoft.com/en-us/library/system.runtime.remoting.proxies.realproxy.aspx" href="http://msdn.microsoft.com/en-us/library/system.runtime.remoting.proxies.realproxy.aspx">http://msdn.microsoft.com/en-us/library/system.runtime.remoting.proxies.realproxy.aspx</a></p> <p><a title="CodeProject- Using AOP in C#. Free source code and programming help" href="http://www.codeproject.com/KB/cs/UsingAOPInCSharp.aspx">CodeProject- Using AOP in C#. Free source code and programming help</a></p> <p><a title="http://www.geocities.com/aspectdotnet/" href="http://www.geocities.com/aspectdotnet/">http://www.geocities.com/aspectdotnet/</a></p> <p><a href="http://www.xwang.org/post/AOPIntroducation.html" target="_blank">AOP Introducation</a></p> <p>本来想写一个AOP实现的例子，无奈功力似乎浅了点，对于AOP的三种实现缺乏整体的把握，想想还是暂时搁浅好了, 也太晚了点 :) 。</p><img src ="http://www.cnblogs.com/zhzkl/aggbug/1287190.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42977/" target="_blank">[新闻]微软首次打破先例 Windows 7不再改名</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>我眼中的Scrum和MSF</title><link>http://www.cnblogs.com/zhzkl/archive/2008/08/20/1272167.html</link><dc:creator>xwang</dc:creator><author>xwang</author><pubDate>Wed, 20 Aug 2008 05:48:00 GMT</pubDate><guid>http://www.cnblogs.com/zhzkl/archive/2008/08/20/1272167.html</guid><wfw:comment>http://www.cnblogs.com/zhzkl/comments/1272167.html</wfw:comment><comments>http://www.cnblogs.com/zhzkl/archive/2008/08/20/1272167.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/zhzkl/comments/commentRss/1272167.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/zhzkl/services/trackbacks/1272167.html</trackback:ping><description><![CDATA[<p>使用Scrum也有几个星期了，和之前难忘的MSF流程比较，有些感触，一起分享. :)<img style="margin: 4px" height="240" src="http://www.infoq.com/resource/minibooks/scrum-xp-from-the-trenches/zh/cover/scrum-and-xp-cover.jpg" width="169" align="right">&nbsp; </p> <p><strong>概念:</strong></p> <p>什么是SCRUM?</p> <p>SCRUM是一种流程，有人说是方法论，而他自己则说自己是框架。是新兴的敏捷过程的一种。</p> <p>什么是MSF?</p> <p>MSF也是流程, 传统的软件开发过程，广泛运用于微软内部流程改进, 分为CMMI版本和Agile版本。</p> <p>&nbsp;</p> <p>他们都关注沟通，反思，需求，不同的是我觉得SCRUM更加人性化并且给出了具体的实施指南。MSF则更讲求框架，但是实际上可实施上并不够好，每一层都要求很严格，而SCRUM则将对质量的关注涉及到每一个方方面面，同时结合XP的开发方式，也很COOL哦。听说微软一些团队也开始使用SCRUM了。</p> <p>关于MSF的流程在安装TFS时就已经安装好了，他的人员组成，文档模板都已经设计好了，需要的是具体管理人员在不同情况下的不同反应而已。 </p> <p>而对于SCRUM虽然没有具体的模板，但是一些技巧和解决问题的方式确实很值得提倡的，每日15分钟例会，Sprint, Story, 产品经理，发布计划，评估等等。SCRUM可以应用于各种团队的管理而不仅仅是软件开发。</p> <p>从几个方面做一下比较好了</p> <table style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid; border-left: #dddddd 1px solid; border-bottom: #dddddd 1px solid" cellspacing="0" cellpadding="2" width="645" border="0"> <tbody> <tr> <td style="border-right: #dddddd 1px solid" valign="top" width="81">&nbsp;</td> <td style="border-right: #dddddd 1px solid" valign="top" width="71"><strong>需求</strong></td> <td style="border-right: #dddddd 1px solid" valign="top" width="35"><strong>文档</strong></td> <td style="border-right: #dddddd 1px solid" valign="top" width="72"><strong>编程方式</strong></td> <td style="border-right: #dddddd 1px solid" valign="top" width="84"><strong>会议</strong></td> <td style="border-right: #dddddd 1px solid" valign="top" width="61"><strong>测试</strong></td> <td style="border-right: #dddddd 1px solid" valign="top" width="43"><strong>实施</strong></td> <td style="border-right: #dddddd 1px solid" valign="top" width="85"><strong>团队</strong></td> <td style="border-right: #dddddd 1px solid" valign="top" width="108"><strong>演示</strong></td></tr> <tr> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="80">MSF(Agile)</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="71">确定签字后无法更改</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="38">强调文档</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="72">传统方式，可结合TDD</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="84">自行安排</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="60">始终伴随</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="45">有实施部署阶段</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="84">沟通与改进</td> <td style="border-top: #dddddd 1px solid" valign="top" width="106">交付时</td></tr> <tr> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="81">SCRUM</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="71">可以修改</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="40">弱化文档</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="72">TDD + XP</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="84">每天15分钟，方式不限, 2~4星期的Sprit</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="60">始终伴随</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="46">持续集成</td> <td style="border-right: #dddddd 1px solid; border-top: #dddddd 1px solid" valign="top" width="84">沟通与改进，提倡固定的Team</td> <td style="border-top: #dddddd 1px solid" valign="top" width="106">2~4星期就会沟通演示，同时反思，修改下一步计划</td></tr></tbody></table> <p>图1: 我眼中的异同</p> <p>当然了实际情况中，MSF也可以有持续集成，本身是一个不同的概念，我喜欢的是里面提供的实践指南，当然了有了实际指南，理论也不能丢，知之敏捷为何也很重要。感谢INFOQ和李剑的翻译。</p> <p>有几段觉得很好玩的话一起enjoy一下, :o)</p> <blockquote> <p><strong>奴役式做法</strong>：对他们说，“你们今天可以给大伙儿干干杂活。倒咖啡、做按摩、清理垃圾、做午饭，一切一切大家今天让你们做的事情。”你会惊讶的发现 Joe 和 Lisa 在霎那之间就找出了有用的技术任务 )</p></blockquote> <p>本文右边的插图即是一本大伙都推荐的SCRUM书籍,&nbsp; Go(中文版):</p> <p><a title="http://www.infoq.com/resource/minibooks/scrum-xp-from-the-trenches/zh/pdf/scrum-and-xp-chinese-version.pdf" href="http://www.infoq.com/resource/minibooks/scrum-xp-from-the-trenches/zh/pdf/scrum-and-xp-chinese-version.pdf">http://www.infoq.com/resource/minibooks/scrum-xp-from-the-trenches/zh/pdf/scrum-and-xp-chinese-version.pdf</a></p> <p>另外CodePlex 上也有了SCRUM for TFS的模板: Go: </p> <p><a href="http://www.codeplex.com/VSTSScrum">VSTS Scrum Process Template</a></p><img src ="http://www.cnblogs.com/zhzkl/aggbug/1272167.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42976/" target="_blank">[新闻]亚马逊EC2云计算计划支持Windows操作系统</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>Understanding Struct, 理解Struct</title><link>http://www.cnblogs.com/zhzkl/archive/2008/08/20/1271807.html</link><dc:creator>xwang</dc:creator><author>xwang</author><pubDate>Tue, 19 Aug 2008 16:02:00 GMT</pubDate><guid>http://www.cnblogs.com/zhzkl/archive/2008/08/20/1271807.html</guid><wfw:comment>http://www.cnblogs.com/zhzkl/comments/1271807.html</wfw:comment><comments>http://www.cnblogs.com/zhzkl/archive/2008/08/20/1271807.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/zhzkl/comments/commentRss/1271807.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/zhzkl/services/trackbacks/1271807.html</trackback:ping><description><![CDATA[<p>在.Net 中各种基本类型都是由struct定义，他与引用类型相有一些不同，有自己的特色，这篇BLOG由ECMA335中关于Value Type的定义开始</p>
<p>用Class定义的类型不一定都是引用类型，实际上，值类型就不是(例如：ValueType).用Class定义的ValueType包含了<strong>拆箱的值类型和关联的装箱类型</strong>. (ECMA335 Partition I, 8.9.7) </p>
<p><a href="/images/cnblogs_com/zhzkl/WindowsLiveWriter/UnderstandingStructStruct_15153/image_2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://www.cnblogs.com/images/cnblogs_com/zhzkl/WindowsLiveWriter/UnderstandingStructStruct_15153/image_thumb.png" border="0" alt="ValueType Has A Corresponding Reference Type" width="616" height="46" /></a>&nbsp; </p>
<ol>
<li>当调用ValueType上的非静态方法时, this 指针是指向一个托管实例的引用，他会调用关联的装箱类型的方法.</li>
<li>值类型本身不支持接口，但是他关联的装箱的类型会.</li>
<li>值类型不能继承</li>
<li>装箱类型的基类不应该包含任何字段.</li>
<li>与引用类型不一样，值类型在创建实例时不需要调用构造函数. 默认他会把所有的字段根据类型设置为null或者0. </li>
</ol>
<h3><strong>关于Struct类型使用的一般规则:</strong></h3>
<p>1. 不能定义无参数默认构造函数</p>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">struct</span> Employee</pre>
<pre><span style="color: #606060">   2:</span>     {</pre>
<pre><span style="color: #606060">   3:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Name;</pre>
<pre><span style="color: #606060">   4:</span>         </pre>
<pre><span style="color: #606060">   5:</span>         <span style="color: #0000ff">public</span> Employee(<span style="color: #0000ff">string</span> name)</pre>
<pre><span style="color: #606060">   6:</span>         {</pre>
<pre><span style="color: #606060">   7:</span>             <span style="color: #0000ff">this</span>.Name = name;</pre>
<pre><span style="color: #606060">   8:</span>         }</pre>
<pre><span style="color: #606060">   9:</span>         </pre>
<pre><span style="color: #606060">  10:</span>         <span style="color: #0000ff">public</span> Employee()</pre>
<pre><span style="color: #606060">  11:</span>         {</pre>
<pre><span style="color: #606060">  12:</span>         }</pre>
<pre><span style="color: #606060">  13:</span>         </pre>
<pre><span style="color: #606060">  14:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Run()</pre>
<pre><span style="color: #606060">  15:</span>         {</pre>
<pre><span style="color: #606060">  16:</span>             Console.WriteLine(<span style="color: #006080">"HI, I am {0}"</span>, Name);</pre>
<pre><span style="color: #606060">  17:</span>         }</pre>
<pre><span style="color: #606060">  18:</span>     }</pre>
</div>
</div>
<p>错误信息: Structs cannot contain explicit parameterless constructors (Structs 不能包含显示的无参构造)</p>
<p>2. 不能初始化</p>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">struct</span> Employee</pre>
<pre><span style="color: #606060">   2:</span>     {</pre>
<pre><span style="color: #606060">   3:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Name = <span style="color: #006080">"Hello"</span>;</pre>
<pre><span style="color: #606060">   4:</span>     }</pre>
</div>
</div>
<p>错误信息: 'Roger.Testing.Employee.Name': cannot have instance field initializers in structs (Structs中不能包含有初始化后的字段)</p>
<p>3. Read-Only状态不能更改</p>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre><span style="color: #606060">   1:</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">readonly</span> Employee emp = <span style="color: #0000ff">new</span> Employee(<span style="color: #006080">"Roger"</span>);</pre>
<pre><span style="color: #606060">   2:</span>         </pre>
<pre><span style="color: #606060">   3:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main()</pre>
<pre><span style="color: #606060">   4:</span>         {</pre>
<pre><span style="color: #606060">   5:</span>             emp.Name = <span style="color: #006080">"New Roger"</span>;</pre>
<pre><span style="color: #606060">   6:</span>             </pre>
<pre><span style="color: #606060">   7:</span>             Console.Read();</pre>
<pre><span style="color: #606060">   8:</span>         }</pre>
</div>
</div>
<p>错误信息: Fields of static readonly field 'Roger.Testing.Testing.emp' cannot be assigned to (except in a static constructor or a variable initializer)&nbsp; readonly类型的Struct不能被赋值, 除非在<strong>静态构造函数</strong>或者变量初始化时可以修改</p>
<p>例子: </p>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre><span style="color: #606060">   1:</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">readonly</span> Employee emp = <span style="color: #0000ff">new</span> Employee(<span style="color: #006080">"Roger"</span>);</pre>
<pre><span style="color: #606060">   2:</span>         </pre>
<pre><span style="color: #606060">   3:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main()</pre>
<pre><span style="color: #606060">   4:</span>         {            </pre>
<pre><span style="color: #606060">   5:</span>             </pre>
<pre><span style="color: #606060">   6:</span>             Console.Read();</pre>
<pre><span style="color: #606060">   7:</span>         }</pre>
<pre><span style="color: #606060">   8:</span>         </pre>
<pre><span style="color: #606060">   9:</span>         <span style="color: #0000ff">static</span> Testing()</pre>
<pre><span style="color: #606060">  10:</span>         {</pre>
<pre><span style="color: #606060">  11:</span>             emp.Name = <span style="color: #006080">"New Roger"</span>;</pre>
<pre><span style="color: #606060">  12:</span>         }</pre>
</div>
</div>
<p>&nbsp;</p>
<p>4. 不能继承</p>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">struct</span> Manager : Employee</pre>
<pre><span style="color: #606060">   2:</span>     {</pre>
<pre><span style="color: #606060">   3:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Title;</pre>
<pre><span style="color: #606060">   4:</span>     }</pre>
</div>
</div>
<p>错误信息: 类型'Employee' 在接口列表中但不是接口</p>
<p>5. Struct可以继承无数接口</p>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">struct</span> Manager : IComparable, ICloneable</pre>
<pre><span style="color: #606060">   2:</span>         {</pre>
<pre><span style="color: #606060">   3:</span>&nbsp; </pre>
<pre><span style="color: #606060">   4:</span>             <span style="color: #cc6633">#region</span> IComparable Members</pre>
<pre><span style="color: #606060">   5:</span>&nbsp; </pre>
<pre><span style="color: #606060">   6:</span>             <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> CompareTo(<span style="color: #0000ff">object</span> obj)</pre>
<pre><span style="color: #606060">   7:</span>             {</pre>
<pre><span style="color: #606060">   8:</span>                 <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> NotImplementedException();</pre>
<pre><span style="color: #606060">   9:</span>             }</pre>
<pre><span style="color: #606060">  10:</span>&nbsp; </pre>
<pre><span style="color: #606060">  11:</span>             <span style="color: #cc6633">#endregion</span></pre>
<pre><span style="color: #606060">  12:</span>&nbsp; </pre>
<pre><span style="color: #606060">  13:</span>             <span style="color: #cc6633">#region</span> ICloneable Members</pre>
<pre><span style="color: #606060">  14:</span>&nbsp; </pre>
<pre><span style="color: #606060">  15:</span>             <span style="color: #0000ff">public</span> <span style="color: #0000ff">object</span> Clone()</pre>
<pre><span style="color: #606060">  16:</span>             {</pre>
<pre><span style="color: #606060">  17:</span>                 <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> NotImplementedException();</pre>
<pre><span style="color: #606060">  18:</span>             }</pre>
<pre><span style="color: #606060">  19:</span>&nbsp; </pre>
<pre><span style="color: #606060">  20:</span>             <span style="color: #cc6633">#endregion</span></pre>
<pre><span style="color: #606060">  21:</span>         }</pre>
</div>
</div>
<p>6. StructLayout</p>
<p>详细解释: <a title="http://www.cnblogs.com/happyhippy/articles/717028.html" href="/happyhippy/articles/717028.html">http://www.cnblogs.com/happyhippy/articles/717028.html</a></p>
<p>7. 序列化Struct</p>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre><span style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">byte</span>[]</pre>
<pre><span style="color: #606060">   2:</span>     RawSerialize(<span style="color: #0000ff">object</span> anything)</pre>
<pre><span style="color: #606060">   3:</span> {</pre>
<pre><span style="color: #606060">   4:</span>     <span style="color: #0000ff">int</span> rawsize =</pre>
<pre><span style="color: #606060">   5:</span>         Marshal.SizeOf(anything);</pre>
<pre><span style="color: #606060">   6:</span>     IntPtr buffer =</pre>
<pre><span style="color: #606060">   7:</span>         Marshal.AllocHGlobal(rawsize);</pre>
<pre><span style="color: #606060">   8:</span>     Marshal.StructureToPtr(anything,</pre>
<pre><span style="color: #606060">   9:</span>         buffer, <span style="color: #0000ff">false</span>);</pre>
<pre><span style="color: #606060">  10:</span>     <span style="color: #0000ff">byte</span>[] rawdata = <span style="color: #0000ff">new</span> <span style="color: #0000ff">byte</span>[rawsize];</pre>
<pre><span style="color: #606060">  11:</span>     Marshal.Copy(buffer, rawdata,</pre>
<pre><span style="color: #606060">  12:</span>         0, rawsize);</pre>
<pre><span style="color: #606060">  13:</span>     Marshal.FreeHGlobal(buffer);</pre>
<pre><span style="color: #606060">  14:</span>     <span style="color: #0000ff">return</span> rawdata;</pre>
<pre><span style="color: #606060">  15:</span> }</pre>
</div>
</div>
<p>8. 调用API</p>
<p>详细解释: <a title="http://www.yesky.com/165/1621165.shtml" href="http://www.yesky.com/165/1621165.shtml">http://www.yesky.com/165/1621165.shtml</a></p>
<h3><strong>Struct类型上的方法调用</strong></h3>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre><span style="color: #606060">   1:</span> <span style="color: #0000ff">using</span> System;</pre>
<pre><span style="color: #606060">   2:</span> <span style="color: #0000ff">using</span> System.Collections.Generic;</pre>
<pre><span style="color: #606060">   3:</span>&nbsp; </pre>
<pre><span style="color: #606060">   4:</span> <span style="color: #0000ff">namespace</span> Roger.Testing</pre>
<pre><span style="color: #606060">   5:</span> {</pre>
<pre><span style="color: #606060">   6:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Testing</pre>
<pre><span style="color: #606060">   7:</span>     {    </pre>
<pre><span style="color: #606060">   8:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main()</pre>
<pre><span style="color: #606060">   9:</span>         {</pre>
<pre><span style="color: #606060">  10:</span>             Employee e = <span style="color: #0000ff">new</span> Employee(<span style="color: #006080">"www.xwang.org"</span>);</pre>
<pre><span style="color: #606060">  11:</span>             e.Run();</pre>
<pre><span style="color: #606060">  12:</span>             </pre>
<pre><span style="color: #606060">  13:</span>             Console.Read();</pre>
<pre><span style="color: #606060">  14:</span>         }</pre>
<pre><span style="color: #606060">  15:</span>     }</pre>
<pre><span style="color: #606060">  16:</span>     </pre>
<pre><span style="color: #606060">  17:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">struct</span> Employee</pre>
<pre><span style="color: #606060">  18:</span>     {</pre>
<pre><span style="color: #606060">  19:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Name;</pre>
<pre><span style="color: #606060">  20:</span>         </pre>
<pre><span style="color: #606060">  21:</span>         <span style="color: #0000ff">public</span> Employee(<span style="color: #0000ff">string</span> name)</pre>
<pre><span style="color: #606060">  22:</span>         {</pre>
<pre><span style="color: #606060">  23:</span>             <span style="color: #0000ff">this</span>.Name = name;</pre>
<pre><span style="color: #606060">  24:</span>         }</pre>
<pre><span style="color: #606060">  25:</span>         </pre>
<pre><span style="color: #606060">  26:</span>         <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Run()</pre>
<pre><span style="color: #606060">  27:</span>         {</pre>
<pre><span style="color: #606060">  28:</span>             Console.WriteLine(<span style="color: #006080">"HI, I am {0}"</span>, Name);</pre>
<pre><span style="color: #606060">  29:</span>         }</pre>
<pre><span style="color: #606060">  30:</span>     }</pre>
<pre><span style="color: #606060">  31:</span> }</pre>
</div>
</div>
<p>编译IL</p>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre><span style="color: #606060">   1:</span> .method <span style="color: #0000ff">public</span> hidebysig <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span>  Main() cil managed</pre>
<pre><span style="color: #606060">   2:</span> {</pre>
<pre><span style="color: #606060">   3:</span>   .entrypoint</pre>
<pre><span style="color: #606060">   4:</span>   <span style="color: #008000">// Code size       26 (0x1a)</span></pre>
<pre><span style="color: #606060">   5:</span>   .maxstack  2</pre>
<pre><span style="color: #606060">   6:</span>   .locals init (valuetype Roger.Testing.Employee V_0)</pre>
<pre><span style="color: #606060">   7:</span>   IL_0000:  ldloca.s   V_0</pre>
<pre><span style="color: #606060">   8:</span>   IL_0002:  ldstr      <span style="color: #006080">"www.xwang.org"</span></pre>
<pre><span style="color: #606060">   9:</span>   IL_0007:  call       instance <span style="color: #0000ff">void</span> Roger.Testing.Employee::.ctor(<span style="color: #0000ff">string</span>)</pre>
<pre><span style="color: #606060">  10:</span>   IL_000c:  ldloca.s   V_0</pre>
<pre><span style="color: #606060">  11:</span>   IL_000e:  call       instance <span style="color: #0000ff">void</span> Roger.Testing.Employee::Run()</pre>
<pre><span style="color: #606060">  12:</span>   IL_0013:  call       int32 [mscorlib]System.Console::Read()</pre>
<pre><span style="color: #606060">  13:</span>   IL_0018:  pop</pre>
<pre><span style="color: #606060">  14:</span>   IL_0019:  ret</pre>
<pre><span style="color: #606060">  15:</span> } <span style="color: #008000">// end of method Testing::Main</span></pre>
</div>
</div>
<p>
大家可以看到
</p>
<p>IL_0007:&nbsp; call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; instance void Roger.Testing.Employee::.Run()</p>
<p>实际上就是调用了开头所说的第一条. :). </p>
<p><span style="color: red">和朋友讨论，说难道是每一次方法调用就会产生一次装箱而后调用方法吗？<br />
正如开文所言，Struct的this指针会指向在内存中的方法，将Struct作为第一个参数传给方法，而后执行 (自己没有去内存布局里面看，也没有确认了 :))。</span></p>
<p>int, double等都属于值类型范畴，所以本身调用方式一致 </p>
<p>再看看WINDBG 中方法表的组成</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_104934" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_104934').style.display='none'; document.getElementById('Code_Open_Image_104934').style.display='inline'; document.getElementById('Code_Open_Text_104934').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" alt="" width="11" height="16" align="top" /><img id="Code_Open_Image_104934" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_104934').style.display='none'; getElementById('Code_Closed_Image_104934').style.display='inline'; getElementById('Code_Closed_Text_104934').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" alt="" width="11" height="16" align="top" /><span id="Code_Closed_Text_104934" class="cnblogs_code_Collapse">WinDBG Run 方法代码</span><span id="Code_Open_Text_104934" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" /><span style="color: #800080">0</span><span style="color: #000000">:</span><span style="color: #800080">003</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">DumpMT&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">md&nbsp;001430bc<br />
</span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />EEClass:&nbsp;</span><span style="color: #800080">00141328</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />Module:&nbsp;00142c4c<br />
</span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />Name:&nbsp;MyStruct<br />
</span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />mdToken:&nbsp;</span><span style="color: #800080">02000003</span><span style="color: #000000">&nbsp;&nbsp;(C:\Users\xwang\Desktop\StructMethod.exe)<br />
</span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />BaseSize:&nbsp;</span><span style="color: #800080">0xc</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />ComponentSize:&nbsp;</span><span style="color: #800080">0x0</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />Number&nbsp;of&nbsp;IFaces&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;IFaceMap:&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />Slots&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;VTable:&nbsp;</span><span style="color: #800080">7</span><span style="color: #000000"><br />
</span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000">--------------------------------------</span><span style="color: #000000"><br />
</span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />MethodDesc&nbsp;Table<br />
</span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />&nbsp;&nbsp;&nbsp;Entry&nbsp;MethodDesc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JIT&nbsp;Name<br />
</span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />5f835100&nbsp;&nbsp;&nbsp;5f2166cc&nbsp;&nbsp;&nbsp;PreJIT&nbsp;System.ValueType.ToString()<br />
</span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />5f3a6920&nbsp;&nbsp;&nbsp;5f216698&nbsp;&nbsp;&nbsp;PreJIT&nbsp;System.ValueType.Equals(System.Object)<br />
</span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />5f357b50&nbsp;&nbsp;&nbsp;5f2166c0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NONE&nbsp;System.ValueType.GetHashCode()<br />
</span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />5f82f960&nbsp;&nbsp;&nbsp;5f216650&nbsp;&nbsp;&nbsp;PreJIT&nbsp;System.Object.Finalize()<br />
</span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />0014c04d&nbsp;&nbsp;&nbsp;0014308c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NONE&nbsp;MyStruct.get_Name()<br />
</span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />0014c051&nbsp;&nbsp;&nbsp;</span><span style="color: #800080">00143098</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NONE&nbsp;MyStruct.set_Name(System.String)<br />
</span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" alt="" align="top" />0014c055&nbsp;&nbsp;&nbsp;001430a4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NONE&nbsp;MyStruct.Run()</span></span></div>
<p>方法表中包含了RUN方法的调用，进一步证实了一个Associated Boxed&nbsp;Type的存在.</p><img src ="http://www.cnblogs.com/zhzkl/aggbug/1271807.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42976/" target="_blank">[新闻]亚马逊EC2云计算计划支持Windows操作系统</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item></channel></rss>