<?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>孙立文的博客 &#187; Todo</title>
	<atom:link href="http://sunliwen.com/category/todo/feed/" rel="self" type="application/rss+xml" />
	<link>http://sunliwen.com</link>
	<description>Never lose my passion!</description>
	<lastBuildDate>Sat, 21 Jan 2012 05:16:52 +0000</lastBuildDate>
	<language>zh</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>使用.NET泛型集合(Generic Collection)</title>
		<link>http://sunliwen.com/2008/12/generic-collection-in-dotnet/</link>
		<comments>http://sunliwen.com/2008/12/generic-collection-in-dotnet/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 16:17:06 +0000</pubDate>
		<dc:creator>Liwen</dc:creator>
				<category><![CDATA[Todo]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://thinklouder.cn/?p=602</guid>
		<description><![CDATA[StackOverflow上看到一个关于泛型类型检查的问题。 定义一个泛型类时，可以使用where关键字对初始化时用做类型参数(type arguments)的类型加以约束(constraints )。如果不符合约束则抛出编译时错误(compile-time error)。 支持的约束有： 约束 描述 where T : struct 类型参数必须是值类型。除了Nullable。 where T : class 类型参数必须是引用类型，包括类、接口、委托和数组。 where T : new() 类型参数必须包含一个公共的无参构造函数，这个约束必须放在所有的其他约束之后。 where T : &#60;base_class_name&#62; 类型参数必须是此基类或者此基类的派生类 where T : &#60;interface_name&#62; 类型参数必须实现指定接口，可以指定多接口，或者泛型接口。 where T : U T的类型参数必须是U，或者U的类型参数派生类。所谓裸类型约束(naked type constraint)。 .NET泛型支持，泛型参数，泛型接口，泛型方法等。Code Project上一篇讲解.Net泛型集合的文章。 C5项目 CollectionBase应该是Java中的Set，是众多集合的基类。 Java集合与C5集合对比 Java中的 C5中的 java.util.Set C5.CollectionBase java.util.HashSet C5.HashSet java.util.List C5.IList java.util.TreeSet C5.TreeSet [...]]]></description>
			<content:encoded><![CDATA[<p>StackOverflow上看到一个关于泛型类型检查的<a href="http://stackoverflow.com/questions/8941/generic-type-checking">问题</a>。<br />
定义一个泛型类时，可以使用where关键字对初始化时用做类型参数(type arguments)的类型加以<a href="http://msdn.microsoft.com/en-us/library/d5x73970.aspx">约束</a>(constraints )。如果不符合约束则抛出编译时错误(compile-time error)。<br />
支持的约束有：</p>
<table border="1">
<tbody>
<tr>
<th>约束</th>
<th>描述</th>
</tr>
<tr>
<td>where T : struct</td>
<td>类型参数必须是值类型。除了<a href="http://msdn.microsoft.com/en-us/library/2cf62fcy.aspx">Nullable</a>。</td>
</tr>
<tr>
<td>where T : class</td>
<td>类型参数必须是引用类型，包括类、接口、委托和数组。</td>
</tr>
<tr>
<td>where T : new()</td>
<td>类型参数必须包含一个公共的无参构造函数，这个约束必须放在所有的其他约束之后。</td>
</tr>
<tr>
<td style="white-space: nowrap;">where T : &lt;base_class_name&gt;</td>
<td>类型参数必须是此基类或者此基类的派生类</td>
</tr>
<tr>
<td style="white-space: nowrap;">where T : &lt;interface_name&gt;</td>
<td>类型参数必须实现指定接口，可以指定多接口，或者泛型接口。</td>
</tr>
<tr>
<td>where T : U</td>
<td>T的类型参数必须是U，或者U的类型参数派生类。所谓裸类型约束(naked type constraint)。</td>
</tr>
</tbody>
</table>
<p><a href="http://msdn.microsoft.com/en-us/library/512aeb7t.aspx">.NET泛型</a>支持，泛型参数，泛型接口，泛型方法等。Code Project上一篇讲解.Net泛型集合的<a href="http://www.codeproject.com/KB/recipes/genericset.aspx">文章</a>。</p>
<p>C5项目<br />
CollectionBase应该是Java中的Set，是众多集合的基类。</p>
<p>Java<a href="http://java.sun.com/j2se/1.5.0/docs/guide/collections/overview.html">集合</a>与C5集合对比</p>
<table border="1">
<tbody>
<tr>
<th>Java中的</th>
<th>C5中的</th>
</tr>
<tr>
<td>java.util.Set</td>
<td>C5.CollectionBase</td>
</tr>
<tr>
<td>java.util.HashSet</td>
<td>C5.HashSet</td>
</tr>
<tr>
<td>java.util.List</td>
<td>C5.IList</td>
</tr>
<tr>
<td>java.util.TreeSet</td>
<td>C5.TreeSet</td>
</tr>
<tr>
<td>java.util.Collection</td>
<td>C5.ICollection</td>
</tr>
<tr>
<td>java.util.Map</td>
<td>C5.IDictionary</td>
</tr>
</tbody>
</table>
<p>使用1:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Set</span> newHead <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HashSet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>使用2:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Map</span> head <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HashMap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Collection</span> entries <span style="color: #339933;">:</span> head.<span style="color: #006633;">values</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>使用3:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span>  <span style="color: #003399;">List</span> asList<span style="color: #009900;">&#40;</span>T... <span style="color: #006633;">a</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="ckepop">
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_douban"></a>
	<a class="jiathis_button_instapaper"></a>
	<a class="jiathis_button_stubleupon"></a>
	<a href="http://www.jiathis.com/share?uid=1544311" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript">var jiathis_config = {data_track_clickback:true};</script>
<script type="text/javascript" src="http://v2.jiathis.com/code_mini/jia.js?uid=1544311" charset="utf-8"></script>
<!-- JiaThis Button END --></div><hr />
<p>
<small>
Tags: <a href="http://sunliwen.com/tag/dotnet/" rel="tag">.NET</a><br/>
<a href="http://sunliwen.com/2008/12/generic-collection-in-dotnet/#comments-heading">没有评论</a>
</small>
</p>]]></content:encoded>
			<wfw:commentRss>http://sunliwen.com/2008/12/generic-collection-in-dotnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CLR如何创建运行时对象</title>
		<link>http://sunliwen.com/2008/12/how-clr-creates-runtime-objects/</link>
		<comments>http://sunliwen.com/2008/12/how-clr-creates-runtime-objects/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 08:20:24 +0000</pubDate>
		<dc:creator>Liwen</dc:creator>
				<category><![CDATA[Todo]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[CLR]]></category>

		<guid isPermaLink="false">http://www.thinklouder.cn/?p=66</guid>
		<description><![CDATA[MSDN Mag上的Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects 一文描述了CLR创建对象时的过程。 Tags: .NET, CLR 没有评论]]></description>
			<content:encoded><![CDATA[<p>MSDN Mag上的<a href="http://msdn.microsoft.com/en-us/magazine/cc163791.aspx"><em>Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects</em></a> 一文描述了CLR创建对象时的过程。</p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="ckepop">
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_douban"></a>
	<a class="jiathis_button_instapaper"></a>
	<a class="jiathis_button_stubleupon"></a>
	<a href="http://www.jiathis.com/share?uid=1544311" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript">var jiathis_config = {data_track_clickback:true};</script>
<script type="text/javascript" src="http://v2.jiathis.com/code_mini/jia.js?uid=1544311" charset="utf-8"></script>
<!-- JiaThis Button END --></div><hr />
<p>
<small>
Tags: <a href="http://sunliwen.com/tag/dotnet/" rel="tag">.NET</a>, <a href="http://sunliwen.com/tag/clr/" rel="tag">CLR</a><br/>
<a href="http://sunliwen.com/2008/12/how-clr-creates-runtime-objects/#comments-heading">没有评论</a>
</small>
</p>]]></content:encoded>
			<wfw:commentRss>http://sunliwen.com/2008/12/how-clr-creates-runtime-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

