﻿<?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/ustbwuyi/</link><description>.NET技术研究进行中....</description><language>zh-cn</language><lastBuildDate>Sun, 21 Mar 2010 14:11:53 GMT</lastBuildDate><pubDate>Sun, 21 Mar 2010 14:11:53 GMT</pubDate><ttl>60</ttl><item><title>JQuery实现的纯JS列表控件</title><link>http://www.cnblogs.com/ustbwuyi/archive/2009/05/14/1456396.html</link><dc:creator>ustbwuyi</dc:creator><author>ustbwuyi</author><pubDate>Wed, 13 May 2009 16:44:00 GMT</pubDate><guid>http://www.cnblogs.com/ustbwuyi/archive/2009/05/14/1456396.html</guid><description><![CDATA[<p>阅读: 468 评论: 0 作者: <a href="http://www.cnblogs.com/ustbwuyi/" target="_blank">ustbwuyi</a> 发表于 2009-05-14 00:44 <a href="http://www.cnblogs.com/ustbwuyi/archive/2009/05/14/1456396.html" target="_blank">原文链接</a></p><p>老婆睡了，随手写点代码，貌似明天要用到。</p>
<p>&nbsp;</p>
<p>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="ProcessTable.aspx.cs" Inherits="ProcessTable" %&gt;</p>
<p>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;<br />
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;<br />
&lt;head runat="server"&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;title&gt;无标题页&lt;/title&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;link href="App_Themes/Main/Main.css" rel="stylesheet" type="text/css" /&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;script src="JavaScript/jquery-1[1].2.6-vsdoc.js" type="text/javascript"&gt;&lt;/script&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;script language="javascript" type="text/javascript"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function DeleteCurrentRow(obj) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#gridTable a").click(function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($(this).attr("id") == obj.id) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (confirm("are you sure to delete this one?")) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).parent().parent().remove();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function EditCurrentRow(obj) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#gridTable a").click(function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($(this).attr("id") == obj.id) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).parent().parent().find("td").not(":last").each(function(i) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var html = $(this).html();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).html("&lt;input type='text' value='" + html + "' /&gt;&lt;input type='hidden' value='" + html + "' /&gt;");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var random = new Date().getTime();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).parent().html("&lt;a href='#' id='update" + random + "' onclick='UpdateRow(this)'&gt;update&lt;/a&gt;&amp;nbsp;&lt;a href='#' id='cancel" + random + "' onclick='CancelRow(this)'&gt;cancel&lt;/a&gt;");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Update<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function UpdateRow(obj) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#gridTable a").click(function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($(this).attr("id") == obj.id) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).parent().parent().find("td").not(":last").each(function(i) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var html = $(this).find("input[@type=text]").val();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).html(html);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var random = new Date().getTime();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).parent().html("&lt;a href=# id='update" + random + "' onclick='EditRow(this)'&gt;edit&lt;/a&gt;&amp;nbsp;&lt;a href=# id='delete" + random + "' onclick='DeleteRow(this)'&gt;delete&lt;/a&gt;");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#newID").show();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Cancel<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function CancelRow(obj) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#gridTable a").click(function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($(this).attr("id") == obj.id) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).parent().parent().find("td").not(":last").each(function(i) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var html = $(this).find("input[@type=hidden]").val();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).html(html);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var random = new Date().getTime();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).parent().html("&lt;a href=# id='update" + random + "' onclick='EditRow(this)'&gt;edit&lt;/a&gt;&amp;nbsp;&lt;a href=# id='delete" + random + "' onclick='DeleteRow(this)'&gt;delete&lt;/a&gt;");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Edit<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function EditRow(obj) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#gridTable a").click(function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($(this).attr("id") == obj.id) {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).parent().parent().find("td").not(":last").each(function(i) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var html = $(this).html();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).html("&lt;input type='text' value='" + html + "' /&gt;&lt;input type='hidden' value='" + html + "' /&gt;");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var random = new Date().getTime();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).hide();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).parent().html("&lt;a href='#' id='update" + random + "' onclick='UpdateRow(this)'&gt;update&lt;/a&gt;&amp;nbsp;&lt;a href='#' id='cancel" + random + "' onclick='CancelRow(this)'&gt;cancel&lt;/a&gt;");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Delete<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function DeleteRow(obj) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#gridTable a").click(function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($(this).attr("id") == obj.id) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (confirm("are you sure to delete this one?")) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).parent().parent().remove();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Insert<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function InsertRow() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var html = "&lt;tr&gt;";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#gridTable tr:last").find("td").not(":last").each(function(i) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; html += "&lt;td&gt;";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; html += "&lt;input type='text' /&gt;";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; html += "&lt;/td&gt;";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var random = new Date().getTime();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; html += "&lt;td&gt;&lt;a href=# id='update" + random + "' onclick='UpdateRow(this)'&gt;update&lt;/a&gt;&amp;nbsp;&lt;a href=# onclick='CancelNew()'&gt;cancel&lt;/a&gt;&lt;/td&gt;";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; html += "&lt;/tr&gt;";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#gridTable").html($("#gridTable").html() + html);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#newID").hide();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; event.returnValue = false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function CancelNew() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#gridTable").find("tr:last").remove();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#newID").show();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; function Submit() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($("#gridTable").find("input").length) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert('can\' submit!');<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $("#gridTable tr").each(function(i) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).find("td").not(":last").each(function(j) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert($(this).html());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; &lt;/script&gt;</p>
<p>&lt;/head&gt;<br />
&lt;body&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;form id="form1" runat="server"&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;div&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div style="height: 30px"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:GridView ID="gridTable" runat="server" Width="500px" AutoGenerateColumns="false"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Columns&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:TemplateField ItemStyle-Width="20%" HeaderText="姓名"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ItemTemplate&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;%# Eval("Name") %&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ItemTemplate&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:TemplateField&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:TemplateField ItemStyle-Width="65%" HeaderText="地址"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ItemTemplate&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;%# Eval("Address") %&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ItemTemplate&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:TemplateField&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:TemplateField&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ItemTemplate&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;a href="#" id="edit" onclick="EditCurrentRow(this)"&gt;edit&lt;/a&gt; &lt;a href="#" id="delete"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; onclick="DeleteCurrentRow(this)"&gt;delete&lt;/a&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ItemTemplate&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:TemplateField&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Columns&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:GridView&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;a href="#" id="newID" onclick="InsertRow()"&gt;Add New&lt;/a&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;br /&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;a href="#" id="submit" onclick="Submit()"&gt;Submit&lt;/a&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</p>
<img src="http://www.cnblogs.com/ustbwuyi/aggbug/1456396.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/ustbwuyi/archive/2009/05/14/1456396.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/ustbwuyi/archive/2009/05/14/1456396.html#commentform" target="_blank">发表评论</a></p><p><a href="http://job.cnblogs.com/" target="_blank">找优秀程序员，就在博客园</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/59295/" target="_blank">9大IT科技公司总部览</a><span style="color:gray">(2010-03-21 21:00)</span><br/>· <a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><span style="color:gray">(2010-03-21 19:51)</span><br/>· <a href="http://news.cnblogs.com/n/59292/" target="_blank">意大利研发出“移动虚拟校园”技术</a><span style="color:gray">(2010-03-21 19:33)</span><br/>· <a href="http://news.cnblogs.com/n/59291/" target="_blank">如果 Facebook 是一个国家，它将是第三大人口国</a><span style="color:gray">(2010-03-21 17:50)</span><br/>· <a href="http://news.cnblogs.com/n/59290/" target="_blank">德国公司推出Android平板电脑WePad</a><span style="color:gray">(2010-03-21 17:43)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>关于.NET邮件的收发问题总结(带附件)</title><link>http://www.cnblogs.com/ustbwuyi/archive/2007/05/28/762581.html</link><dc:creator>ustbwuyi</dc:creator><author>ustbwuyi</author><pubDate>Mon, 28 May 2007 07:29:00 GMT</pubDate><guid>http://www.cnblogs.com/ustbwuyi/archive/2007/05/28/762581.html</guid><description><![CDATA[<p>阅读: 4632 评论: 22 作者: <a href="http://www.cnblogs.com/ustbwuyi/" target="_blank">ustbwuyi</a> 发表于 2007-05-28 15:29 <a href="http://www.cnblogs.com/ustbwuyi/archive/2007/05/28/762581.html" target="_blank">原文链接</a></p><P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 最近因为项目需要，研究了一下邮件的发送和接收，发现现在这方面的问题很多.虽然网上这方面的资料很多，但是真正应用起来<BR>仍然会发现不少问题，而且很多人都抱怨书上或者网上的一些代码应用起来是失败的，并且针对附件方面的处理不太完善，针对这种情况我把最近研究所得做一个小小的总结，希望能对大家有所帮助。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 首先来谈谈发送邮件的问题。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 发送邮件现在应用得最多的两种情况就是利用.NET自带的发送邮件和利用jmail组件来发送邮件。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .NET自带的邮件发送利用了System.Web.Mail.MailMessage这个类，这是在VS2003的情况下，在VS2005下更多的是利用System.Net.Mail.MailMessage，下面的例子是在VS2003的情况下写的,请在应用的时候自己替换掉里面的参数。<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;SendTos</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">SendTo.Text.Trim();　　</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">发送人</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;CcTos</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">CcTo.Text.Trim();&nbsp;&nbsp;　　&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">抄送人</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">[]&nbsp;Receiver</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">System.Text.RegularExpressions.Regex.Split(SendTos</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">CcTos,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">总收件人</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;FromMail</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">ustbwuyi1@163.com</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">发件人</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;Title</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">你好</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">邮件主题</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;Body</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">附件里重要文档,请查收!</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">邮件主体</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;ShowName</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">ustbwuyi</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">显示名字</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(SendTos</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">||</SPAN><SPAN style="COLOR: #000000">&nbsp;CcTos</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_369_987_Open_Image onclick="this.style.display='none'; Codehighlighter1_369_987_Open_Text.style.display='none'; Codehighlighter1_369_987_Closed_Image.style.display='inline'; Codehighlighter1_369_987_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_369_987_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_369_987_Closed_Text.style.display='none'; Codehighlighter1_369_987_Open_Image.style.display='inline'; Codehighlighter1_369_987_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_369_987_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_369_987_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">用户名(取发送邮箱的@前面的部分,即ustbwuyi1</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;MailUserName</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">FromMail.Substring(</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,FromMail.IndexOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">@</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">密码</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;MailPassword</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">ustbwuyi</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Web.Mail.MailMessage&nbsp;mailmessage</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;MailMessage();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mailmessage.From</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">FromMail;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mailmessage.Subject</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">Title;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mailmessage.Body</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">Body;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">添加附件</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ArrayList&nbsp;FileNames;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">如果存在附件</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(FileNames.Count</SPAN><SPAN style="COLOR: #000000">&gt;=</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_754_981_Open_Image onclick="this.style.display='none'; Codehighlighter1_754_981_Open_Text.style.display='none'; Codehighlighter1_754_981_Closed_Image.style.display='inline'; Codehighlighter1_754_981_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_754_981_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_754_981_Closed_Text.style.display='none'; Codehighlighter1_754_981_Open_Image.style.display='inline'; Codehighlighter1_754_981_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_754_981_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_754_981_Open_Text><SPAN style="COLOR: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">添加附件</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;Filename;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;k</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;k</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">FileNames.Count;k</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_843_971_Open_Image onclick="this.style.display='none'; Codehighlighter1_843_971_Open_Text.style.display='none'; Codehighlighter1_843_971_Closed_Image.style.display='inline'; Codehighlighter1_843_971_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_843_971_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_843_971_Closed_Text.style.display='none'; Codehighlighter1_843_971_Open_Image.style.display='inline'; Codehighlighter1_843_971_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_843_971_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_843_971_Open_Text><SPAN style="COLOR: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Filename</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">FileNames[k].ToString();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mailmessage.Attachments.Add(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;MailAttachment(Filename));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mailmessage.Fields.Add(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">http://schemas.microsoft.com/cdo/configuration/smtpauthenticate</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mailmessage.Fields.Add(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">http://schemas.microsoft.com/cdo/configuration/sendusername</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,MailUserName);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mailmessage.Fields.Add(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">http://schemas.microsoft.com/cdo/configuration/sendpassword</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,MailPassword);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">向收件人和抄送人循环发送</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;j</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;j</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">Receiver.Length;j</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_1373_1703_Open_Image onclick="this.style.display='none'; Codehighlighter1_1373_1703_Open_Text.style.display='none'; Codehighlighter1_1373_1703_Closed_Image.style.display='inline'; Codehighlighter1_1373_1703_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_1373_1703_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1373_1703_Closed_Text.style.display='none'; Codehighlighter1_1373_1703_Open_Image.style.display='inline'; Codehighlighter1_1373_1703_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1373_1703_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1373_1703_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mailmessage.To</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">Receiver[j].ToString();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Web.Mail.SmtpMail.SmtpServer</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">smtp.163.com</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_1490_1547_Open_Image onclick="this.style.display='none'; Codehighlighter1_1490_1547_Open_Text.style.display='none'; Codehighlighter1_1490_1547_Closed_Image.style.display='inline'; Codehighlighter1_1490_1547_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1490_1547_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1490_1547_Closed_Text.style.display='none'; Codehighlighter1_1490_1547_Open_Image.style.display='inline'; Codehighlighter1_1490_1547_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1490_1547_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1490_1547_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Web.Mail.SmtpMail.Send(mailmessage);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(Exception&nbsp;ex)<BR><IMG id=Codehighlighter1_1579_1697_Open_Image onclick="this.style.display='none'; Codehighlighter1_1579_1697_Open_Text.style.display='none'; Codehighlighter1_1579_1697_Closed_Image.style.display='inline'; Codehighlighter1_1579_1697_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1579_1697_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1579_1697_Closed_Text.style.display='none'; Codehighlighter1_1579_1697_Open_Image.style.display='inline'; Codehighlighter1_1579_1697_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1579_1697_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1579_1697_Open_Text><SPAN style="COLOR: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;script&nbsp;language='javascript'&gt;alert('邮件发送失败,请您和ustbwuyi联系(QQ:108556024)！')&lt;/script&gt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN></DIV>
<P>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 上面的例子是利用163的SMTP邮件服务器来发送邮件，当然，如果你有自己的邮件服务器更好。</P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其次，是利用jmail组件来发送，现在jmail组件的版本很多，在这里我个人推荐jmail4.4pro版本，因为如果你要收邮件的话，必须用pro版本，另外，个人经过测试了其它几个版本，发现只有这个版本不会出现附件丢失的情况，其他几个版本都会出现附件丢失或者损坏的情况，这个对txt文件来说没有影响，但是对于传送图片或者其他的一些压缩文件，会发现从pop服务器上下过来的附件有一些损坏，从而不能正常打开文件。下面是jmail发送邮件的代码。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">jmail.MessageClass&nbsp;MyMail&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;jmail.MessageClass();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;SendTos</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">SendTo.Text.Trim();　　</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">发送人</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;CcTos</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">CcTo.Text.Trim();&nbsp;&nbsp;　　&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">抄送人</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">[]&nbsp;Receiver</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">System.Text.RegularExpressions.Regex.Split(SendTos</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">CcTos,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">总收件人</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;FromMail</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">ustbwuyi1@163.com</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">发件人</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;Title</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">你好</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">邮件主题</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;Body</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">附件里是重要文档,请查收!</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">邮件主体</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;ShowName</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">ustbwuyi</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">显示名字<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">取email的@前面部分为用户名,即ustbwuyi1,当然也可以自己设置.</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;MailUserName</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">FromMail.Substring(</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,FromMail.IndexOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">@</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;MailPassword</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">ustbwuyi</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(SendTos</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">||</SPAN><SPAN style="COLOR: #000000">&nbsp;CcTos</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_571_1697_Open_Image onclick="this.style.display='none'; Codehighlighter1_571_1697_Open_Text.style.display='none'; Codehighlighter1_571_1697_Closed_Image.style.display='inline'; Codehighlighter1_571_1697_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_571_1697_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_571_1697_Closed_Text.style.display='none'; Codehighlighter1_571_1697_Open_Image.style.display='inline'; Codehighlighter1_571_1697_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_571_1697_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_571_1697_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;字符集</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.Charset&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">GB2312</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">附件的编码格式</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.Encoding&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">BASE64</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG id=Codehighlighter1_666_691_Open_Image onclick="this.style.display='none'; Codehighlighter1_666_691_Open_Text.style.display='none'; Codehighlighter1_666_691_Closed_Image.style.display='inline'; Codehighlighter1_666_691_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_666_691_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_666_691_Closed_Text.style.display='none'; Codehighlighter1_666_691_Open_Image.style.display='inline'; Codehighlighter1_666_691_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_666_691_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_666_691_Open_Text><SPAN style="COLOR: #808080">///</SPAN><SPAN style="COLOR: #008000">/是否将信头编码成iso-8859-1字符集</SPAN><SPAN style="COLOR: #808080"></SPAN></SPAN><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.ISOEncodeHeaders&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">发送人邮件地址</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.From&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;FromMail;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">发送人姓名</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.FromName&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;ShowName;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;邮件主题</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.Subject&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">Title;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">身份验证的用户名</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.MailServerUserName&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;MailUserName;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">用户密码</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.MailServerPassWord&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;MailPassword;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">邮件内容</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.Body&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Body;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ArrayList&nbsp;FileNames;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">如果存在附件</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(FileNames.Count</SPAN><SPAN style="COLOR: #000000">&gt;=</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_1103_1365_Open_Image onclick="this.style.display='none'; Codehighlighter1_1103_1365_Open_Text.style.display='none'; Codehighlighter1_1103_1365_Closed_Image.style.display='inline'; Codehighlighter1_1103_1365_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1103_1365_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1103_1365_Closed_Text.style.display='none'; Codehighlighter1_1103_1365_Open_Image.style.display='inline'; Codehighlighter1_1103_1365_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1103_1365_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1103_1365_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">添加附件</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;Filename;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;k</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;k</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">FileNames.Count;k</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_1188_1355_Open_Image onclick="this.style.display='none'; Codehighlighter1_1188_1355_Open_Text.style.display='none'; Codehighlighter1_1188_1355_Closed_Image.style.display='inline'; Codehighlighter1_1188_1355_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1188_1355_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1188_1355_Closed_Text.style.display='none'; Codehighlighter1_1188_1355_Open_Image.style.display='inline'; Codehighlighter1_1188_1355_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1188_1355_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1188_1355_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Filename</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">FileNames[k].ToString();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.AddAttachment(Filename,</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">,HttpUtility.UrlDecode(Filename.Substring(Filename.LastIndexOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">3</SPAN><SPAN style="COLOR: #000000">)));<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_1380_1548_Open_Image onclick="this.style.display='none'; Codehighlighter1_1380_1548_Open_Text.style.display='none'; Codehighlighter1_1380_1548_Closed_Image.style.display='inline'; Codehighlighter1_1380_1548_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1380_1548_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1380_1548_Closed_Text.style.display='none'; Codehighlighter1_1380_1548_Open_Image.style.display='inline'; Codehighlighter1_1380_1548_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1380_1548_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1380_1548_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">循环发送</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;i</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">Receiver.Length;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_1439_1533_Open_Image onclick="this.style.display='none'; Codehighlighter1_1439_1533_Open_Text.style.display='none'; Codehighlighter1_1439_1533_Closed_Image.style.display='inline'; Codehighlighter1_1439_1533_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1439_1533_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1439_1533_Closed_Text.style.display='none'; Codehighlighter1_1439_1533_Open_Image.style.display='inline'; Codehighlighter1_1439_1533_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1439_1533_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1439_1533_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.AddRecipient(Receiver[i],</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MyMail.Send(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Mail.rshi.cn</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(Exception&nbsp;ex)<BR><IMG id=Codehighlighter1_1578_1692_Open_Image onclick="this.style.display='none'; Codehighlighter1_1578_1692_Open_Text.style.display='none'; Codehighlighter1_1578_1692_Closed_Image.style.display='inline'; Codehighlighter1_1578_1692_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1578_1692_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1578_1692_Closed_Text.style.display='none'; Codehighlighter1_1578_1692_Open_Image.style.display='inline'; Codehighlighter1_1578_1692_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1578_1692_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1578_1692_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;script&nbsp;language='javascript'&gt;alert('邮件发送失败,请您和ustbwuyi联系(QQ:108556024)！')&lt;/script&gt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN></DIV>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 好了，现在我们来看看接收邮件的问题。一般来说，接收邮件主要分为两部分，一是将接收到的邮件的信息保存到数据库，如邮件的<BR>主题，内容，发送人，发送时间等。其次是对邮件附件的处理，主要将邮件附件从POP服务器上下载下来并保存到数据库，然后将附件<BR>信息保存到数据库，如附件的路径，附件对应的邮件编号等信息。这一点.NET自带的似乎并不太好处理，没有jmail组件处理方便，<BR>当然关于.NET自带的我并没有深入研究，个人经过比较还是推荐jmail，当然前面说过关于jmail几个版本在这方面的差异，所以个人<BR>还是推荐jmail4.4pro版本。下面是收邮件的代码：<BR><BR>&nbsp; </P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;ReceiveMails(</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;Username)<BR><IMG id=Codehighlighter1_45_2541_Open_Image onclick="this.style.display='none'; Codehighlighter1_45_2541_Open_Text.style.display='none'; Codehighlighter1_45_2541_Closed_Image.style.display='inline'; Codehighlighter1_45_2541_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_45_2541_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_45_2541_Closed_Text.style.display='none'; Codehighlighter1_45_2541_Open_Image.style.display='inline'; Codehighlighter1_45_2541_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_45_2541_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_45_2541_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jmail.Message&nbsp;Msg</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;jmail.Message();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jmail.POP3&nbsp;jpop&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;jmail.POP3();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jmail.Attachments&nbsp;atts;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jmail.Attachment&nbsp;att;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">username为用户名,该方法通过用户名获取该用户的pop设置,即用户的POP用户名,密码,POP服务器地址以及端口号这四个参数,这四个参数是连接POP服务器的必用参数.</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SqlDataReader&nbsp;dataReader&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.ExtGetSetting(Username);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(dataReader.Read())<BR><IMG id=Codehighlighter1_371_2537_Open_Image onclick="this.style.display='none'; Codehighlighter1_371_2537_Open_Text.style.display='none'; Codehighlighter1_371_2537_Closed_Image.style.display='inline'; Codehighlighter1_371_2537_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_371_2537_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_371_2537_Closed_Text.style.display='none'; Codehighlighter1_371_2537_Open_Image.style.display='inline'; Codehighlighter1_371_2537_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_371_2537_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_371_2537_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(dataReader[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">PopServer</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString()</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">&amp;&amp;</SPAN><SPAN style="COLOR: #000000">dataReader[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">PopUsername</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString()</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_468_2527_Open_Image onclick="this.style.display='none'; Codehighlighter1_468_2527_Open_Text.style.display='none'; Codehighlighter1_468_2527_Closed_Image.style.display='inline'; Codehighlighter1_468_2527_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_468_2527_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_468_2527_Closed_Text.style.display='none'; Codehighlighter1_468_2527_Open_Image.style.display='inline'; Codehighlighter1_468_2527_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_468_2527_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_468_2527_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">连接POP服务器</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jpop.Connect(dataReader[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">PopUsername</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString(),dataReader[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">PopPassword</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString(),dataReader[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">PopServer</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString(),Int32.Parse(dataReader[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">PopPort</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString()));<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">如果服务器上有邮件</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(jpop.Count</SPAN><SPAN style="COLOR: #000000">&gt;=</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_711_2432_Open_Image onclick="this.style.display='none'; Codehighlighter1_711_2432_Open_Text.style.display='none'; Codehighlighter1_711_2432_Closed_Image.style.display='inline'; Codehighlighter1_711_2432_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_711_2432_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_711_2432_Closed_Text.style.display='none'; Codehighlighter1_711_2432_Open_Image.style.display='inline'; Codehighlighter1_711_2432_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_711_2432_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_711_2432_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">;i</SPAN><SPAN style="COLOR: #000000">&lt;=</SPAN><SPAN style="COLOR: #000000">jpop.Count;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_758_2418_Open_Image onclick="this.style.display='none'; Codehighlighter1_758_2418_Open_Text.style.display='none'; Codehighlighter1_758_2418_Closed_Image.style.display='inline'; Codehighlighter1_758_2418_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_758_2418_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_758_2418_Closed_Text.style.display='none'; Codehighlighter1_758_2418_Open_Image.style.display='inline'; Codehighlighter1_758_2418_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_758_2418_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_758_2418_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Msg&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;jpop.Messages[i];<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;atts</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">Msg.Attachments;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">取数据库中邮件信息中的最大发送时间,即最近接收到的一封邮件的时间</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Database&nbsp;dbase</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Database();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataTable&nbsp;data</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">dbase.GetDataTable(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">select&nbsp;max(MailSendDate)&nbsp;as&nbsp;MailSenderDate&nbsp;from&nbsp;TabMailList&nbsp;where&nbsp;MailTypeFlag='1'</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">对服务器上的邮件的发送时间和数据库最近一封邮件的时间进行比较,如果大那么证明该邮件还未被收取,是一封新邮件,这样避免重复收取邮件入库</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(Msg.Date</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">Convert.ToDateTime(data.Rows[</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">][</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">].ToString()))<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_1205_2402_Open_Image onclick="this.style.display='none'; Codehighlighter1_1205_2402_Open_Text.style.display='none'; Codehighlighter1_1205_2402_Closed_Image.style.display='inline'; Codehighlighter1_1205_2402_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1205_2402_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1205_2402_Closed_Text.style.display='none'; Codehighlighter1_1205_2402_Open_Image.style.display='inline'; Codehighlighter1_1205_2402_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1205_2402_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1205_2402_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">将这封新邮件的信息保存到数据库</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.SaveExtMail(Msg,Username,dataReader[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Email</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString(),jpop.GetMessageUID(i));<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">获取附件上传到服务器并且将信息存入数据库</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(atts.Count</SPAN><SPAN style="COLOR: #000000">&gt;=</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_1404_2382_Open_Image onclick="this.style.display='none'; Codehighlighter1_1404_2382_Open_Text.style.display='none'; Codehighlighter1_1404_2382_Closed_Image.style.display='inline'; Codehighlighter1_1404_2382_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1404_2382_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1404_2382_Closed_Text.style.display='none'; Codehighlighter1_1404_2382_Open_Image.style.display='inline'; Codehighlighter1_1404_2382_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1404_2382_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1404_2382_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;k</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;k</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">atts.Count;k</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_1456_2371_Open_Image onclick="this.style.display='none'; Codehighlighter1_1456_2371_Open_Text.style.display='none'; Codehighlighter1_1456_2371_Closed_Image.style.display='inline'; Codehighlighter1_1456_2371_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1456_2371_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1456_2371_Closed_Text.style.display='none'; Codehighlighter1_1456_2371_Open_Image.style.display='inline'; Codehighlighter1_1456_2371_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1456_2371_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1456_2371_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;att</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">atts[k];</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">获得附件</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;attname</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">att.Name;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_1552_2246_Open_Image onclick="this.style.display='none'; Codehighlighter1_1552_2246_Open_Text.style.display='none'; Codehighlighter1_1552_2246_Closed_Image.style.display='inline'; Codehighlighter1_1552_2246_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1552_2246_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1552_2246_Closed_Text.style.display='none'; Codehighlighter1_1552_2246_Open_Image.style.display='inline'; Codehighlighter1_1552_2246_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_1552_2246_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1552_2246_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Random&nbsp;TempNameInt&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Random();&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;NewMailDirName&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;TempNameInt.Next(</SPAN><SPAN style="COLOR: #000000">100000000</SPAN><SPAN style="COLOR: #000000">).ToString();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\AttachFiles\\</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">Username</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">NewMailDirName);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;mailPath</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\AttachFiles\\</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">Username</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">NewMailDirName</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\\</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">attname;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;att.SaveToFile(System.Web.HttpContext.Current.Server.MapPath(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">mailPath);&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">获取该封邮件在数据库的ID,以便和附件信息相对应,取邮件表中的最大ID即可&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;mailID</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.GetMailID();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">将附件信息存入数据库</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.AttExtSend(mailID,attname,att.Size,mailPath,Msg.From);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(Exception&nbsp;ex)<BR><IMG id=Codehighlighter1_2290_2348_Open_Image onclick="this.style.display='none'; Codehighlighter1_2290_2348_Open_Text.style.display='none'; Codehighlighter1_2290_2348_Closed_Image.style.display='inline'; Codehighlighter1_2290_2348_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_2290_2348_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2290_2348_Closed_Text.style.display='none'; Codehighlighter1_2290_2348_Open_Image.style.display='inline'; Codehighlighter1_2290_2348_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_2290_2348_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_2290_2348_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throw</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Exception(ex.Message);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">删除服务器上的邮件</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jpop.DeleteMessages();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">断开连接&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jpop.Disconnect();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN></DIV>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 至于将邮件信息和附件信息如何存入数据库，就看你自己对表的设计了，我就不多说了，经过上面就可以完全将你ＰＯＰ服务器上的<BR>邮件完全接收到你的本地了。<BR><BR><BR><BR><BR></P><img src="http://www.cnblogs.com/ustbwuyi/aggbug/762581.html?type=1" width="1" height="1" alt=""/><p>评论: 22　<a href="http://www.cnblogs.com/ustbwuyi/archive/2007/05/28/762581.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/ustbwuyi/archive/2007/05/28/762581.html#commentform" target="_blank">发表评论</a></p><p><a href="http://job.cnblogs.com/" target="_blank">找优秀程序员，就在博客园</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/59295/" target="_blank">9大IT科技公司总部览</a><span style="color:gray">(2010-03-21 21:00)</span><br/>· <a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><span style="color:gray">(2010-03-21 19:51)</span><br/>· <a href="http://news.cnblogs.com/n/59292/" target="_blank">意大利研发出“移动虚拟校园”技术</a><span style="color:gray">(2010-03-21 19:33)</span><br/>· <a href="http://news.cnblogs.com/n/59291/" target="_blank">如果 Facebook 是一个国家，它将是第三大人口国</a><span style="color:gray">(2010-03-21 17:50)</span><br/>· <a href="http://news.cnblogs.com/n/59290/" target="_blank">德国公司推出Android平板电脑WePad</a><span style="color:gray">(2010-03-21 17:43)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title> C#2.0新特性之泛型与迭代器</title><link>http://www.cnblogs.com/ustbwuyi/archive/2007/04/12/711015.html</link><dc:creator>ustbwuyi</dc:creator><author>ustbwuyi</author><pubDate>Thu, 12 Apr 2007 09:43:00 GMT</pubDate><guid>http://www.cnblogs.com/ustbwuyi/archive/2007/04/12/711015.html</guid><description><![CDATA[<p>阅读: 501 评论: 1 作者: <a href="http://www.cnblogs.com/ustbwuyi/" target="_blank">ustbwuyi</a> 发表于 2007-04-12 17:43 <a href="http://www.cnblogs.com/ustbwuyi/archive/2007/04/12/711015.html" target="_blank">原文链接</a></p><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><B><SPAN style="FONT-SIZE: 15pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">泛型</SPAN></B><B><SPAN style="FONT-SIZE: 15pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">1</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">什么是泛型？</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">　泛型允许你在编译时间实现类型安全。它们允许你创建一个数据结构而不限于特定的数据类型。即通过参数化类型来实现在同一份代码上操作多种数据类型。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">泛型编程是一种编程范式，它利用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">“</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">参数化类型</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">”</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">将类型抽象化，从而实现更为灵活的复用。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">之所以我们称它为泛型，是因为我们在定义的时候，只为它所包含的对象指派了一个类型占位符，而不是将它定义为确定的类型，只有在创建该集合的实例时，才会给它指派一个确定的类型。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">2</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">、泛型的优点</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">我们都知道，泛型是</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">.NET2.0</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">里面新引入的特性，至于泛型的作用，我们都知道，它只是使</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C#</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">里面的类型免去了相互转换的麻烦和复杂度。而且，我们也知道，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">.NET</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">是一个单根继承系统，即</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">.NET</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">里面所有的类都是单继承的，一个类不能继承多个类，即一个派生类不能继承多个基类，这一点和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C++</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">是不同的。另外，在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C#</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">里面，所有的类型都可以作为</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Object</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">来进行传递，也就是说，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Object</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">类实际上完全可以实现泛型的功能。既然如此，那么</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Java</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">.NET</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">为什么还要引入泛型呢？泛型的引入究竟有什么作用呢？</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">我们来归纳一下，泛型和非泛型相比，主要有二个优点。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">首先，泛型更加安全。为什么这么说呢，虽然所有的类型都可以作为</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Object</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">来传递，但是在传递的过程中无法避免进行类型转换，而类型转换在运行的时候是不安全的，在某个时候，它和程序的环境配置以及具体的数据有关，比如曾经我碰到的一个问题就是，将</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">string</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">类型转换成</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">int</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">型的时候，用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">int.parse</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">进行转换，结果在本地运行正常，但是上传到服务器的时候却无法显示网页，结果后来用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Convert.ToInt32</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">转化就正常了。在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C#</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">中，仅整数就有九种类型，它们的范围各不相同，再加上其他类型，如此多的类型，它们相互之间的转换是存在不安全性的因素的，而泛型的使用避免了不必要的类型转换，从而提高了安全性。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">比如，我们来看下面这个例子<BR>&nbsp;&nbsp;&nbsp; </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Stack myStack=new Stack();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>myStack.Push("ustbwuyi");<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>myStack.Push(4);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Array myArray = myStack.ToArray();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>foreach (string item in myArray)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>label1.Text += item + "&lt;br/&gt;";<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">上述的这个例子，我们在编译该函数的时候，程序是不会报错的，而当程序执行的时候，程序才会抱错，这样的话我们很难在编译的时候发现程序中的错误。那么，如果我们用泛型情况又如何呢？</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Stack&lt;string&gt; myStack = new Stack&lt;string&gt;();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>myStack.Push("ustbwuyi1");<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>myStack.Push(5);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Array myArray = myStack.ToArray();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>foreach (string item in myArray)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>label1.Text += item + "&lt;br/&gt;";<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">像上面这种情况在编译的时候就会报错，因为创建该泛型的时候就指定了特定类型</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">string</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">当然，对于</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C#</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">VB.NET</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">来说，在原理上还是有一些区别。比如我来看一个例子。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ArrayList list = new ArrayList();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>list.Add(3);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>list.Add(4);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>list.Add(5.0);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>int total = 0;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>foreach (int i in list)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>total = total + i;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Response.Write(total);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">对于上面的代码，我们可以看到明显是出错的，类型转换上有错误，那么这个错误是怎么引起的，对于</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C#</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">来说，当执行</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">list.Add(3);</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">时，已经将</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">3</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">装箱了，而在循环的时候，该元素将拆箱成</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">int</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">型，而对于</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">list.Add(5.0);</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">来说，程序先将</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">double</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">型</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">5.0</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">装箱，然后再循环的时候该</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">double</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">值被拆箱成</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">int</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">型，所以引发程序的异常。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">对于</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">VB</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">来说，这个过程是有所不同的，因为在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">VB</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">中不使用装箱机制，而是激活一个将</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">double</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">型转化成</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">int</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">类型的方法。但是如果这个值不能被转化为整形，那么这个过程也是失败的。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">其次，泛型的效率更高，在非泛型编程中，将简单类型作为</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Object</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">传递会引起装箱和拆箱操作，这两个过程是具有很大的系统开销的，而用泛型就不会存在这个问题。比如在栈中添加值类型时，如整数，在添加之前必须装箱。装箱的时候在栈上分配一个对象，该对象包括该值类型的一个引用。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>.NET</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">中的泛型和其它平台的泛型有一些区别，他们具有很好的二进制重用性。这一点主要是因为</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">.NET</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">将泛型内建在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">CLR</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">之中。而</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C++</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Java</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">中的泛型所依靠的是它们各自的编译器所提供的特性，编译器在编译泛型代码时将确切的类型展开，这就难免会出现代码膨胀的问题。而</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">.NET</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">的泛型代码是在运行时由</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">JIT</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">just-in-time,CLR</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">所使用的编译器</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">,</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">负责把</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">MSIL</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">翻译的代码编译成真正的机器代码</SPAN><SPAN lang=EN-US>.</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">）</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">即时编译的，这样</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">CLR</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">就可以为不同类型重用大部分的即时编译代码了。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">除此之外，泛型极大的节省了我们的时间，提高了我们的开发效率。我们在创建自定义集合的时候，只需要一行代码，就可以创建一个自定义集合的匹配物，而不用为每种存储类型分别创建不同的独立的集合。只需要在初始化泛型集合的时候将其初始化为一个你需要用到的类型。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">在什么情况下使用泛型？</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>一般来说，在通常情况下，在集合类型中，我们都建议使用泛型，因为它具有类型安全的优点，而不需要从基集合类型派生并实现类型特定的成员。另外，如果集合元素为值类型，泛型集合类型一般都会优于非泛型集合类型，因为在使用泛型的时候不必对元素进行装箱。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">泛型集合的种类？</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>泛型一般来说有下面这些集合类型：</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>1 List，这是我们应用最多的泛型种类，它对应ArrayList集合。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>2 Dictionary，这也是我们平时运用比较多的泛型种类，对应Hashtable集合。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>3 Collection对应于CollectionBase<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>4 ReadOnlyCollection 对应于ReadOnlyCollectionBase,这是一个只读的集合。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>5 Queue,Stack和SortedList，它们分别对应于与它们同名的非泛型类。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">除此之外，还有一些没有对应非泛型类型的泛型种类，这个在我们平时中应用比较少，在这就不多阐述了。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">泛型中的关键字default<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">在泛型的使用过程中，我们经常会遇到这样一种情况。怎样给泛型方法中的参数化类型T设置默认值。因为对于T来说，它的类型是不定的，它可能是值类型，也可能是引用类型。即使知道它是值类型，也有数值和结构之分。这样就给我们定义它的默认值带来了困难，如果我们定义t=null，这只有在T为引用类型时才有效。如果我们定义t=0，这只有在T为数值类型而不是结构时才有效。怎么解决这个问题呢？泛型的解决方案是利用default关键字，这个关键字有什么作用呢？它对引用类型会返回null，对数值类型会返回0，也就是说，它会根据每个结构成员的不同类型来返回不同的默认值。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">public class GenericList&lt;T&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>private class Node<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public Node Next;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public T Data;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>private Node head;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>public T GetNext()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>T temp = default(T);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Node current = head;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (current != null)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>temp = current.Data;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>current = current.Next;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return temp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">虽然泛型的引入虽然给我们带来很多好处，但是同时也使C#中的语法有一些变化，这是我们在使用泛型的过程中应该注意的。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">下面我们着重在类中来讲叙泛型，在实际中它在类方法、接口、委托和结构上都是可以使用的。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">1、泛型中的静态成员变量</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>对于类的静态成员变量来说，在C#1.1中，类的静态成员变量在不同的类实例中是共享的，并且都是通过类名来访问的。在2.0中，这个机制有了一些变化，即静态成员变量在相同封闭类间共享，在不同的封闭类间不共享。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>为什么呢？因为在泛型中，不同的封闭类虽然有相同的类名称，但是传入的数据类型是不同的，它在本质上来说是不同的类。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>比如下面：</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Test&lt;int&gt; a=new Test&lt;int&gt;();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Test&lt;int&gt; b=new Test&lt;int&gt;();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Test&lt;string&gt; c=new Test&lt;string&gt;();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">a和b是同一类型，但是c和a，b是完全不同的类实例，所以它们之间不能共享静态成员变量。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">2、泛型中的方法重载</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>我们知道，方法重载在C#中应用非常广泛，对方法进行重载的时候，要求它们具有不同的签名。但是在对泛型进行重载的时候，通用类型T在编写的时候是不确定的，这是和传统的重载方法所不同的地方，对这种情况我们怎样进行处理呢？下面我们来看这个例子。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">public class Example&lt;T, V&gt; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public T add(T a, V b)<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//第一个add<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return a;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public T add(V a, T b)<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//第二个add<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return b;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>public int add(int a, int b)<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>//第三个add<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return a + b;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">对于上面的类来说，如果我们将T和V都传入int类型的话，那么这三个add方法将具有相同的签名，但是这个类仍然能够通过编译，只有在将这个类实例化并且调用add方法时编译器才能判断是否会引起调用混淆。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>下面我们来看第一种情况，看是否会引起混淆。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">Example&lt;int,int&gt; example1=new Example&lt;int,int&gt;();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">object x=example1.add(1,1);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">如果我们按照上面的情况实例化，类中的三个方法都符合，因为它们具有相同的签名。但是在这里，是可以调用成功的，因为在这里有一个原则：</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">如果一般方法和泛型方法具有相同的签名，一般方法会覆盖泛型方法。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">也就是说，在上面进行实例化的并且调用类中的方法时，第三个方法已经覆盖了前面两个泛型方法，所以在这里是可以调用成功的。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">如果我们删除了第三个add方法，那么上面的代码编译的时候是无法通过的，因为前两个add方法引起了混淆。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">3、泛型类中数据类型的约束</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>在泛型的使用过程中我们经常会遇到这种问题，虽然这个数据类型T是通用类型，但是在有些特殊情况下我们必须对传入的数据进行一定的限制，即我们经常说的泛型的数据类型约束。约束的方式是指定T的祖先，即它继承的接口或者类，这里要注意的是C#是单根继承的，所以约束可以有多个接口，但是最多只能有一个类，并且类必须在接口之前。下面我们来看一个约束。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Public class Test&lt;T,V&gt; where T:Stack,IComparable<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Where<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>V:Stack<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">{</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">…</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">上面这个约束说明，T必须从Stack和Icomparable继承，V必须是Stack或者从Stack继承。否则它是无法通过编译器的类型检查的。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>看到这里有人也许会问，既然T是通用类型，各种数据类型都支持，那还需要对它进行约束干什么呢？不是多此一举吗？其实不然，约束在泛型中是有很重要的作用的，举个例子，比如现在我设计的类只需要两种数据类型int和string，并且需要对T类型的变量比较大小。但是对于object来说，它是没有比较大小的方法的，这是很显然的。这时候我们就可以利用约束来进行处理。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">比如说下面的方法：</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">public static T Max</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">＜</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">T</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">＞</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">(T op1, T op2) <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">　</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">if (op1.CompareTo(op2) </SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">＜</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"> 0)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">　　</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">return op1;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">　</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">return op2;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>} <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">这个例子在编译的时候是不能通过的，因为没有对它添加</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">IComparable</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">约束，没有实现</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">IComparable</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">接口所以不支持</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">CompareTo</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">方法。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">public static T Max</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">＜</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">T</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">＞</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">(T op1, T op2) where T : IComparable<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">　</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">if (op1.CompareTo(op2) </SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">＜</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN"> 0)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">　　</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">return op1;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-ascii-font-family: 'Times New Roman'">　</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">return op2;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-ansi-language: ZH-CN">}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">我们知道，在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C#</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">里数据类型有两大类，值类型和引用类型，在泛型的约束里面，我们也可以指定通用类型</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">T</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">是值类型还是引用类型，值类型用关键字</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">struct</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">来标识，而引用类型用关键字</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">class</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">来标识。如：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Public class Test&lt;T,V&gt; where T:class<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Where V:struct<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">{……}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">如果在类Test里需要对T重新进行实例化，而我们又不知道类Test中类T到底有哪些构造函数。这个时候需要用到new约束：</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">如：</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">public class Test&lt;T, V&gt; where T : Stack, new()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>where V: IComparable<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">要注意的一点是，当与其他约束一起使用时，new() 约束必须最后指定。另外，new约束只能是无参数的，所以也要求相应的类Stack必须有一个无参构造函数，否则编译失败。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">泛型方法：</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">泛型不仅能作用在类上，也可单独用在类的方法上，他可根据方法参数的类型自动适应各种参数，这样的方法叫泛型方法。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">对于下面的泛型方法，</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 新宋体">原来的类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-fareast-font-family: 宋体">Stack</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 新宋体">一次只能</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-fareast-font-family: 宋体">Push</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 新宋体">一个数据，这个类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-fareast-font-family: 宋体">Stack2</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 新宋体">扩展了</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-fareast-font-family: 宋体">Stack</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 新宋体">的功能（当然也可以直接写在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-fareast-font-family: 宋体">Stack</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 新宋体">中），他可以一次把多个数据压入</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-fareast-font-family: 宋体">Stack</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 新宋体">中。其中</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-fareast-font-family: 宋体">Push</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 新宋体">是一个泛型方法。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; COLOR: blue; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">class</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> <SPAN style="COLOR: teal">Program<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">static</SPAN> <SPAN style="COLOR: blue">void</SPAN> Main(<SPAN style="COLOR: blue">string</SPAN>[] args)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Stack</SPAN>&lt;<SPAN style="COLOR: blue">int</SPAN>&gt; x = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: teal">Stack</SPAN>&lt;<SPAN style="COLOR: blue">int</SPAN>&gt;(100);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Stack2</SPAN> x2 = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: teal">Stack2</SPAN>();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>x2.Push(x, 1, 2, 3, 4, 6);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">string</SPAN> s=<SPAN style="COLOR: maroon">""</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">for</SPAN> (<SPAN style="COLOR: blue">int</SPAN> i = 0; i &lt; 5; i++)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>s += x.Pop().ToString();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: teal">Stack2<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>//</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">一个泛型方法，将多个数据压入堆栈</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">void</SPAN> Push&lt;T&gt;(<SPAN style="COLOR: teal">Stack</SPAN>&lt;T&gt; s, <SPAN style="COLOR: blue">params</SPAN> T[] p)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">foreach</SPAN> (T t <SPAN style="COLOR: blue">in</SPAN> p)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>s.Push(t);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: -14.2pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><B><SPAN style="FONT-SIZE: 15pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">迭代器（Iterator）</SPAN></B><B><SPAN style="FONT-SIZE: 15pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -17.95pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">迭代器和泛型一样，也是</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C#2.0</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">中的新功能，迭代器是方法、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">get</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">访问器或者运算符。它是用来干什么的呢？它的主要作用是使类或者结构，包括我们自己定义的数据集等中能够支持</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">foreach</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">遍历。在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C#</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">中，我们主要通过继承</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">IEnumerable</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">接口和实现该接口的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">GetEnumrator</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">方法来创建迭代器。只要我们在程序中提供一个迭代器，就可以遍历类中的数据结构，在程序进行编译的时候，当编译器检测到迭代器，它会自动生成</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">IEnumerable</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">或者</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">IEnumerable</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">接口的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Current</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">MoveNext</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Dispose</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">方法。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -17.95pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">下面我们看一个简单的例子，来看</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">C#</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">是如何实现迭代的。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -17.9pt; TEXT-INDENT: -0.05pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">例一：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: blue; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">public</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: #007f7f">Example1</SPAN>:<SPAN style="COLOR: #007f7f">IEnumerable<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: #007f7f">IEnumerator</SPAN> GetEnumerator()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">for</SPAN> (<SPAN style="COLOR: blue">int</SPAN> i = 0; i &lt; 10; i++)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">yield</SPAN> <SPAN style="COLOR: blue">return</SPAN> i;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -17.9pt; TEXT-INDENT: -0.05pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; COLOR: blue; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">class</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> <SPAN style="COLOR: #007f7f">Program<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">static</SPAN> <SPAN style="COLOR: blue">void</SPAN> Main(<SPAN style="COLOR: blue">string</SPAN>[] args)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #007f7f">Example1</SPAN> test = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #007f7f">Example1</SPAN>();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">foreach</SPAN> (<SPAN style="COLOR: blue">int</SPAN> i <SPAN style="COLOR: blue">in</SPAN> test)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #007f7f">Console</SPAN>.WriteLine(i);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -17.9pt; TEXT-INDENT: -0.05pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -17.85pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">输出结果：</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">0123456789<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -17.85pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -17.85pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">关于迭代器：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -17.85pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt 12.15pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none; mso-list: l0 level1 lfo1; tab-stops: 12.15pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">2<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">迭代器是可以返回相同类型的值的有序序列的一段代码。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt 12.15pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none; mso-list: l0 level1 lfo2; tab-stops: 12.15pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">3<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">迭代器可用作方法、运算符或</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">get</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">访问器的代码体。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt 12.15pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none; mso-list: l0 level1 lfo3; tab-stops: 12.15pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">4<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">迭代器使用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">yield return</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">语句依次返回每个元素，到达</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">yield break</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">将终止迭代。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt 12.15pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none; mso-list: l0 level1 lfo4; tab-stops: 12.15pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">5<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">在一个类中可以实现多个迭代器。但是在一个类里面的迭代器必须有唯一的名称。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt 12.15pt; TEXT-INDENT: -18pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none; mso-list: l0 level1 lfo5; tab-stops: 12.15pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">6<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">迭代器的返回类型必须为</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">IEnumerable</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">IEnumerator</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">类型。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">现在，我们大概知道了迭代器的一些概念，也知道迭代器是用来做什么的，简单的说就是实现对一个类（主要是容器类）或者结构的循环。而它的主要用途也在这里，如果我们不做容器类，并且如果我们不需要实现容器类循环这个需求，那迭代器对我们来说就没有什么用处了。前者没有必要，后者可以直接用容器内部的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">GetEnumerator</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">方法。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">迭代器的实现模式。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">通常情况下，实现</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">IEnumrable</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">接口的类是作为要遍历的集合类型的嵌套类来提供。将嵌套类作为枚举器。这样既可以保证它访问所包含的类的其他私有成员，又对迭代客户端隐藏了底层数据结构的实现细节。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -17.95pt; TEXT-INDENT: 21pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>迭代器中有三个很重要的属性和方法，即</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Current</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">MoveNext</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Dispose</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">方法。下面我们先介绍一下这三个方法。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">MoveNext方法封装了迭代器块的代码，调用MoveNext方法将执行迭代器内的代码。并且将对象的current属性设为合适的值。至于设为什么值，由MoveNext方法被调用时枚举器对象的状态决定。比如如果当前枚举器对象状态是before或者suspended，那么调用MoveNext将把对象的状态改为running。如果当前枚举器对象状态是running，那么调用MoveNext方法的结果是未知的。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">Current属性受yield return语句影响，它的值是最后一次调用MoveNext时被设置的值，当枚举器对象处于before、after或者running时，Current的值是不确定的。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; TEXT-INDENT: 18pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">Dispose方法通过将枚举器对象的状态置为after，以清理迭代结果。如果状态是before，调用Dispose将改变其状态为after；如果状态为running，调用Dispose的结果是为指定的；如果枚举器对象状态为suspended，调用Dispose将先改变其状态为running，并且执行finally块，最后改变其状态为after；如果枚举器对象状态为after，那么调用Dispose没有效果。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>使用迭代器有一个问题我们必须有清晰的认识，那就是，迭代器的主要功能是实现容器类和自定义集合的循环。但是，在我们的实际开发中，容器类和自定义集合都不会是单一的数据类型，肯定包含了多种数据类型。如果包含了值类型，那么需要对它们进行装箱和拆箱才能获得选项。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">因为</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">IEnumerator.Current</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">返回一个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Object</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">类的对象。这必然会导致潜在的性能降低和托管堆上的压力增大。如果包含的是引用类型，那么必然存在类型之间的转换，这样同样是会带来效率的损失和存在一定的安全性问题。那么这个问题怎么解决呢？</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm -25.6pt 0pt -5.85pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">前面我们讲泛型的时候曾经提到了泛型的优点，恰好是避免装箱拆箱，并且避免在类型转换中的安全问题，可以说，泛型的优点正好可以补迭代器在容器类中使用的缺点。所以，在实际的开发过程中，我们一般将迭代器和泛型结合起来使用。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN">最后，我们综合泛型和迭代器来看一个例子，这个例子是微软提供的，我稍微做了一下改动。</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; COLOR: blue; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">public</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: teal">Ustbwuyi</SPAN>&lt;T&gt; : <SPAN style="COLOR: teal">IEnumerable</SPAN>&lt;T&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">protected</SPAN> <SPAN style="COLOR: teal">Node</SPAN> Node1;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">protected</SPAN> <SPAN style="COLOR: teal">Node</SPAN> current = <SPAN style="COLOR: blue">null</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">该嵌套类型同样为</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">T</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">上的泛型</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">protected</SPAN> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: teal">Node<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: teal">Node</SPAN> next;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: teal">Node</SPAN> Next<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">get</SPAN> { <SPAN style="COLOR: blue">return</SPAN> next; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">set</SPAN> { next = <SPAN style="COLOR: blue">value</SPAN>; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">private</SPAN> T data;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> T Data<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">get</SPAN> { <SPAN style="COLOR: blue">return</SPAN> data; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">set</SPAN> { data = <SPAN style="COLOR: blue">value</SPAN>; }<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">在非泛型构造函数中使用</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">T <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> Node(T t)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>next = <SPAN style="COLOR: blue">null</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>data = t;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> Ustbwuyi()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Node1 = <SPAN style="COLOR: blue">null</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">void</SPAN> AddHead(T t)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Node</SPAN> n = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: teal">Node</SPAN>(t);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>n.Next = Node1;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Node1 = n;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">实现</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> GetEnumerator </SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">以返回</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> IEnumerator&lt;T&gt;</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">，从而启用列表的</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// foreach </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">迭代。请注意，在</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> C# 2.0 </SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">中，</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">不需要实现</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> Current </SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">和</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> MoveNext</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">。</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">编译器将创建实现</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> IEnumerator&lt;T&gt; </SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">的类。</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: teal">IEnumerator</SPAN>&lt;T&gt; GetEnumerator()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Node</SPAN> current = Node1;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">while</SPAN> (current != <SPAN style="COLOR: blue">null</SPAN>)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">yield</SPAN> <SPAN style="COLOR: blue">return</SPAN> current.Data;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>current = current.Next;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">必须实现次方法，因为</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">IEnumerable&lt;T&gt; </SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">继承</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> IEnumerable<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">IEnumerator</SPAN> <SPAN style="COLOR: teal">IEnumerable</SPAN>.GetEnumerator()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> GetEnumerator();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;summary&gt;<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">一个排序算法</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;/summary&gt;<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: gray">///</SPAN><SPAN style="COLOR: green"> </SPAN><SPAN style="COLOR: gray">&lt;typeparam name="T"&gt;&lt;/typeparam&gt;<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: teal">SortedList</SPAN>&lt;T&gt; : <SPAN style="COLOR: teal">Ustbwuyi</SPAN>&lt;T&gt; <SPAN style="COLOR: blue">where</SPAN> T : <SPAN style="COLOR: teal">IComparable</SPAN>&lt;T&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">void</SPAN> BubbleSort()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (Node1 == <SPAN style="COLOR: blue">null</SPAN> || Node1.Next == <SPAN style="COLOR: blue">null</SPAN>)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">bool</SPAN> swapped;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">do<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Node</SPAN> previous = <SPAN style="COLOR: blue">null</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Node</SPAN> current = Node1;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>swapped = <SPAN style="COLOR: blue">false</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">while</SPAN> (current.next != <SPAN style="COLOR: blue">null</SPAN>)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (current.Data.CompareTo(current.next.Data) &gt; 0)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Node</SPAN> tmp = current.next;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>current.next = current.next.next;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>tmp.next = current;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (previous == <SPAN style="COLOR: blue">null</SPAN>)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Node1 = tmp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">else<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>previous.next = tmp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>previous = tmp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>swapped = <SPAN style="COLOR: blue">true</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">else<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>previous = current;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>current = current.next;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">while</SPAN> (swapped);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: teal">Person</SPAN> : <SPAN style="COLOR: teal">IComparable</SPAN>&lt;<SPAN style="COLOR: teal">Person</SPAN>&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">string</SPAN> name;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">int</SPAN> age;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> Person(<SPAN style="COLOR: blue">string</SPAN> s, <SPAN style="COLOR: blue">int</SPAN> i)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>name = s;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>age = i;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">int</SPAN> CompareTo(<SPAN style="COLOR: teal">Person</SPAN> p)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> age - p.age;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">override</SPAN> <SPAN style="COLOR: blue">string</SPAN> ToString()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> name + <SPAN style="COLOR: maroon">"</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">的年龄是：</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">"</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> + age;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">bool</SPAN> Equals(<SPAN style="COLOR: teal">Person</SPAN> p)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> (<SPAN style="COLOR: blue">this</SPAN>.age == p.age);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: teal">Program<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">static</SPAN> <SPAN style="COLOR: blue">void</SPAN> Main(<SPAN style="COLOR: blue">string</SPAN>[] args)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">SortedList</SPAN>&lt;<SPAN style="COLOR: teal">Person</SPAN>&gt; list = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: teal">SortedList</SPAN>&lt;<SPAN style="COLOR: teal">Person</SPAN>&gt;();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">string</SPAN>[] names = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: blue">string</SPAN>[] { <SPAN style="COLOR: maroon">"</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">邬琳伟</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">"</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">, <SPAN style="COLOR: maroon">"</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">吴娟</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">"</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">, <SPAN style="COLOR: maroon">"</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">吴倚</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">"</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">, <SPAN style="COLOR: maroon">"</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">胡娭毑</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">"</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">, <SPAN style="COLOR: maroon">"</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">唐志科</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">"</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> };<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">int</SPAN>[] ages = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: blue">int</SPAN>[] { 31, 25, 23, 24, 25 };<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">填充列表</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">for</SPAN> (<SPAN style="COLOR: blue">int</SPAN> i = 0; i &lt; names.Length; i++)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>list.AddHead(<SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: teal">Person</SPAN>(names[i], ages[i]));<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Console</SPAN>.WriteLine(<SPAN style="COLOR: maroon">"</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-font-kerning: 0pt; mso-no-proof: yes">未排序的列表：</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">"</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">);</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">输出未排序的列表</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">foreach</SPAN> (<SPAN style="COLOR: teal">Person</SPAN> p <SPAN style="COLOR: blue">in</SPAN> list)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Console</SPAN>.WriteLine(p.ToString());<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">对列表进行排序</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>list.BubbleSort();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Console</SPAN>.WriteLine(<SPAN style="COLOR: teal">String</SPAN>.Format(<SPAN style="COLOR: maroon">"{0}</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-font-kerning: 0pt; mso-no-proof: yes">排序的列表：</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">"</SPAN><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt">, <SPAN style="COLOR: teal">Environment</SPAN>.NewLine));<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: ZH-CN; mso-font-kerning: 0pt; mso-ascii-font-family: 新宋体">输出排序的列表</SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">foreach</SPAN> (<SPAN style="COLOR: teal">Person</SPAN> p <SPAN style="COLOR: blue">in</SPAN> list)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Console</SPAN>.WriteLine(p.ToString());<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: teal">Console</SPAN>.WriteLine(<SPAN style="COLOR: maroon">"Filished"</SPAN>);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 新宋体; mso-ansi-language: ZH-CN; mso-fareast-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">该程序的输出结果为：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">未排序的列表：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">唐志科的年龄是：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">25<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">胡娭毑的年龄是：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">24<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">吴倚的年龄是：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">23<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">吴娟的年龄是：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">25<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">邬琳伟的年龄是：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">31<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">排序的列表：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">吴倚的年龄是：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">23<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">胡娭毑的年龄是：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">24<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">唐志科的年龄是：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">25<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">吴娟的年龄是：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">25<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">邬琳伟的年龄是：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">31<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">Filished<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'">请按任意键继续</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; LINE-HEIGHT: 150%">. . .<o:p></o:p></SPAN></P><img src="http://www.cnblogs.com/ustbwuyi/aggbug/711015.html?type=1" width="1" height="1" alt=""/><p>评论: 1　<a href="http://www.cnblogs.com/ustbwuyi/archive/2007/04/12/711015.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/ustbwuyi/archive/2007/04/12/711015.html#commentform" target="_blank">发表评论</a></p><p><a href="http://job.cnblogs.com/" target="_blank">找优秀程序员，就在博客园</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/59295/" target="_blank">9大IT科技公司总部览</a><span style="color:gray">(2010-03-21 21:00)</span><br/>· <a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><span style="color:gray">(2010-03-21 19:51)</span><br/>· <a href="http://news.cnblogs.com/n/59292/" target="_blank">意大利研发出“移动虚拟校园”技术</a><span style="color:gray">(2010-03-21 19:33)</span><br/>· <a href="http://news.cnblogs.com/n/59291/" target="_blank">如果 Facebook 是一个国家，它将是第三大人口国</a><span style="color:gray">(2010-03-21 17:50)</span><br/>· <a href="http://news.cnblogs.com/n/59290/" target="_blank">德国公司推出Android平板电脑WePad</a><span style="color:gray">(2010-03-21 17:43)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>ajax完美解决的一个麻烦问题</title><link>http://www.cnblogs.com/ustbwuyi/archive/2007/03/19/679586.html</link><dc:creator>ustbwuyi</dc:creator><author>ustbwuyi</author><pubDate>Mon, 19 Mar 2007 03:26:00 GMT</pubDate><guid>http://www.cnblogs.com/ustbwuyi/archive/2007/03/19/679586.html</guid><description><![CDATA[<p>阅读: 2341 评论: 7 作者: <a href="http://www.cnblogs.com/ustbwuyi/" target="_blank">ustbwuyi</a> 发表于 2007-03-19 11:26 <a href="http://www.cnblogs.com/ustbwuyi/archive/2007/03/19/679586.html" target="_blank">原文链接</a></p><P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 最近老总提了一个小功能，在搜索网吧列表的时候加上网吧所属代理商这个条件，原有的搜索条件是一个地区二级联动，现在需要根据不同的地区显示不同的代理商集合。<BR>即在触发地区下拉框的onchange事件时，代理商的下拉框选项也相应的改变，比如选择地区 湖南—〉长沙，那么代理商下拉框只显示长沙的代理商。<BR>&nbsp;&nbsp;&nbsp; 本来认为这个很好实现，但实际改起来的时候发现问题多多，主要问题是原有的地区联动是用js实现的，它的数据源是一个xml文件，当然如果下拉框是服务器端控件那么问题是很好解决的，现在是html控件一下子似乎还真有些不好改，想了几种办法实现起来都不理想，最后将思路转向用ajax来实现问题才迎刃而解，现在仔细一想，像这种情况似乎只有用ajax才能比较好的解决，如果是在地区下拉框的onchange事件里向后台进行一次提交，将地区下拉框的id传过去的话，实际上产生的回发会将地区联动下拉框重新初始化。<BR>&nbsp;&nbsp;&nbsp; 现在我具体谈谈这个ajax实现的过程。<BR>&nbsp;&nbsp;&nbsp; 首先页面当然需要定义一个下拉框的html控件。</P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">select&nbsp;</SPAN><SPAN style="COLOR: #ff0000">id</SPAN><SPAN style="COLOR: #0000ff">="Agent"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="Agent"</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">select</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV><BR>
<P>接下来当然是定义XmlHttpRequest对象。<BR>&nbsp;&nbsp;&nbsp; </P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">var</SPAN><SPAN style="COLOR: #000000">&nbsp;xmlhttp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">function</SPAN><SPAN style="COLOR: #000000">&nbsp;CreateXmlHttp()<BR><IMG id=Codehighlighter1_41_411_Open_Image onclick="this.style.display='none'; Codehighlighter1_41_411_Open_Text.style.display='none'; Codehighlighter1_41_411_Closed_Image.style.display='inline'; Codehighlighter1_41_411_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_41_411_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_41_411_Closed_Text.style.display='none'; Codehighlighter1_41_411_Open_Image.style.display='inline'; Codehighlighter1_41_411_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_41_411_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_41_411_Open_Text><SPAN style="COLOR: #000000">{&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">非IE浏览器创建XmlHttpRequest对象</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(window.XmlHttpRequest)<BR><IMG id=Codehighlighter1_111_152_Open_Image onclick="this.style.display='none'; Codehighlighter1_111_152_Open_Text.style.display='none'; Codehighlighter1_111_152_Closed_Image.style.display='inline'; Codehighlighter1_111_152_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_111_152_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_111_152_Closed_Text.style.display='none'; Codehighlighter1_111_152_Open_Image.style.display='inline'; Codehighlighter1_111_152_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_111_152_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_111_152_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlhttp</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;XmlHttpRequest();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">IE浏览器创建XmlHttpRequest对象</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(window.ActiveXObject)<BR><IMG id=Codehighlighter1_218_406_Open_Image onclick="this.style.display='none'; Codehighlighter1_218_406_Open_Text.style.display='none'; Codehighlighter1_218_406_Closed_Image.style.display='inline'; Codehighlighter1_218_406_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_218_406_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_218_406_Closed_Text.style.display='none'; Codehighlighter1_218_406_Open_Image.style.display='inline'; Codehighlighter1_218_406_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_218_406_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_218_406_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_232_292_Open_Image onclick="this.style.display='none'; Codehighlighter1_232_292_Open_Text.style.display='none'; Codehighlighter1_232_292_Closed_Image.style.display='inline'; Codehighlighter1_232_292_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_232_292_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_232_292_Closed_Text.style.display='none'; Codehighlighter1_232_292_Open_Image.style.display='inline'; Codehighlighter1_232_292_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_232_292_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_232_292_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlhttp</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ActiveXObject(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Microsoft.XMLHTTP</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(e)<BR><IMG id=Codehighlighter1_311_400_Open_Image onclick="this.style.display='none'; Codehighlighter1_311_400_Open_Text.style.display='none'; Codehighlighter1_311_400_Closed_Image.style.display='inline'; Codehighlighter1_311_400_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_311_400_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_311_400_Closed_Text.style.display='none'; Codehighlighter1_311_400_Open_Image.style.display='inline'; Codehighlighter1_311_400_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_311_400_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_311_400_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_320_377_Open_Image onclick="this.style.display='none'; Codehighlighter1_320_377_Open_Text.style.display='none'; Codehighlighter1_320_377_Closed_Image.style.display='inline'; Codehighlighter1_320_377_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_320_377_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_320_377_Closed_Text.style.display='none'; Codehighlighter1_320_377_Open_Image.style.display='inline'; Codehighlighter1_320_377_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN id=Codehighlighter1_320_377_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_320_377_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlhttp</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ActiveXObject(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">msxml2.XMLHTTP</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_393_394_Open_Image onclick="this.style.display='none'; Codehighlighter1_393_394_Open_Text.style.display='none'; Codehighlighter1_393_394_Closed_Image.style.display='inline'; Codehighlighter1_393_394_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_393_394_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_393_394_Closed_Text.style.display='none'; Codehighlighter1_393_394_Open_Image.style.display='inline'; Codehighlighter1_393_394_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(ex)</SPAN><SPAN id=Codehighlighter1_393_394_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_393_394_Open_Text><SPAN style="COLOR: #000000">{}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN></DIV><BR>
<P>这个在我的多篇blog文章里都有阐述，就不多说了。<BR><BR>接下来当然是利用该对象来发送条件，获得数据,并且将获得的数据绑定到agent这个下拉框。<BR>在地区下拉框的onchange事件里面触发函数AjaxSend()；<BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">function</SPAN><SPAN style="COLOR: #000000">&nbsp;AjaxSend()<BR><IMG id=Codehighlighter1_20_272_Open_Image onclick="this.style.display='none'; Codehighlighter1_20_272_Open_Text.style.display='none'; Codehighlighter1_20_272_Closed_Image.style.display='inline'; Codehighlighter1_20_272_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_20_272_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_20_272_Closed_Text.style.display='none'; Codehighlighter1_20_272_Open_Image.style.display='inline'; Codehighlighter1_20_272_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_20_272_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_20_272_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">创建XmlHttpRequest对象</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CreateXmlHttp();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">!</SPAN><SPAN style="COLOR: #000000">xmlhttp)<BR><IMG id=Codehighlighter1_98_169_Open_Image onclick="this.style.display='none'; Codehighlighter1_98_169_Open_Text.style.display='none'; Codehighlighter1_98_169_Closed_Image.style.display='inline'; Codehighlighter1_98_169_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_98_169_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_98_169_Closed_Text.style.display='none'; Codehighlighter1_98_169_Open_Image.style.display='inline'; Codehighlighter1_98_169_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_98_169_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_98_169_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">创建xmlhttpRequest发生异常！</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">获取地区下拉框的value值，作为条件发送</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">var</SPAN><SPAN style="COLOR: #000000">&nbsp;ss</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">document.getElementById(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">a2</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">).value.substring(</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">4</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">要发送的url，UserAjax我专门用来取数据</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">UserAjax.aspx?area=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">ss;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlhttp.open(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">POST</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,url,</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlhttp.onreadystatechange</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">function</SPAN><SPAN style="COLOR: #000000">()<BR><IMG id=Codehighlighter1_439_1382_Open_Image onclick="this.style.display='none'; Codehighlighter1_439_1382_Open_Text.style.display='none'; Codehighlighter1_439_1382_Closed_Image.style.display='inline'; Codehighlighter1_439_1382_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_439_1382_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_439_1382_Closed_Text.style.display='none'; Codehighlighter1_439_1382_Open_Image.style.display='inline'; Codehighlighter1_439_1382_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_439_1382_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_439_1382_Open_Text><SPAN style="COLOR: #000000">{&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(xmlhttp.readyState</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">4</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_488_1373_Open_Image onclick="this.style.display='none'; Codehighlighter1_488_1373_Open_Text.style.display='none'; Codehighlighter1_488_1373_Closed_Image.style.display='inline'; Codehighlighter1_488_1373_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_488_1373_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_488_1373_Closed_Text.style.display='none'; Codehighlighter1_488_1373_Open_Image.style.display='inline'; Codehighlighter1_488_1373_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_488_1373_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_488_1373_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(xmlhttp.status</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">200</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_540_1360_Open_Image onclick="this.style.display='none'; Codehighlighter1_540_1360_Open_Text.style.display='none'; Codehighlighter1_540_1360_Closed_Image.style.display='inline'; Codehighlighter1_540_1360_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_540_1360_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_540_1360_Closed_Text.style.display='none'; Codehighlighter1_540_1360_Open_Image.style.display='inline'; Codehighlighter1_540_1360_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_540_1360_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_540_1360_Open_Text><SPAN style="COLOR: #000000">{&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">清空原下拉框</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">agent</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">).options.length</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">str为返回的一个字符串，形式为"0001/代理商1,0002/代理商2,0003/代理商3<IMG src="http://www.cnblogs.com/Images/dot.gif">"</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">var</SPAN><SPAN style="COLOR: #000000">&nbsp;str</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">xmlhttp.responseText;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">将该字符串分割为数组形式</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">var</SPAN><SPAN style="COLOR: #000000">&nbsp;strs</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">str.split(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">agent</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">).options.add(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Option(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">----------</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">000000</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #0000ff">var</SPAN><SPAN style="COLOR: #000000">&nbsp;i</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;i</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">strs.length</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_985_1327_Open_Image onclick="this.style.display='none'; Codehighlighter1_985_1327_Open_Text.style.display='none'; Codehighlighter1_985_1327_Closed_Image.style.display='inline'; Codehighlighter1_985_1327_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_985_1327_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_985_1327_Closed_Text.style.display='none'; Codehighlighter1_985_1327_Open_Image.style.display='inline'; Codehighlighter1_985_1327_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_985_1327_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_985_1327_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">获取value值（编号）</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">var</SPAN><SPAN style="COLOR: #000000">&nbsp;a</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">strs[i].substring(</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,strs[i].lastIndexOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">获取绑定内容</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">var</SPAN><SPAN style="COLOR: #000000">&nbsp;b</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">strs[i].substring(strs[i].lastIndexOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,strs.length);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">绑定到下拉框</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">agent</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">).options.add(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Option(b,a));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmlhttp.send();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>}<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN></DIV>
<P>另外顺便介绍一下UserAjax接收到该地区编号后获取数据返回字符串的过程。<BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;Area&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Request.QueryString[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">area</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataTable&nbsp;data&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">生成DataTable，涉及到公司核心代码，省略</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;aa&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;data.Rows.Count;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_189_487_Open_Image onclick="this.style.display='none'; Codehighlighter1_189_487_Open_Text.style.display='none'; Codehighlighter1_189_487_Closed_Image.style.display='inline'; Codehighlighter1_189_487_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_189_487_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_189_487_Closed_Text.style.display='none'; Codehighlighter1_189_487_Open_Image.style.display='inline'; Codehighlighter1_189_487_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_189_487_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_189_487_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(aa&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">)<BR><IMG id=Codehighlighter1_229_331_Open_Image onclick="this.style.display='none'; Codehighlighter1_229_331_Open_Text.style.display='none'; Codehighlighter1_229_331_Closed_Image.style.display='inline'; Codehighlighter1_229_331_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_229_331_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_229_331_Closed_Text.style.display='none'; Codehighlighter1_229_331_Open_Image.style.display='inline'; Codehighlighter1_229_331_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_229_331_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_229_331_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aa&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;data.Rows[i][</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">id</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString()</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">data.Rows[i][</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_362_477_Open_Image onclick="this.style.display='none'; Codehighlighter1_362_477_Open_Text.style.display='none'; Codehighlighter1_362_477_Closed_Image.style.display='inline'; Codehighlighter1_362_477_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_362_477_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_362_477_Closed_Text.style.display='none'; Codehighlighter1_362_477_Open_Image.style.display='inline'; Codehighlighter1_362_477_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_362_477_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_362_477_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aa&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;aa&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;data.Rows[i][</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">id</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString()&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;data.Rows[i][</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">].ToString();<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(aa);</SPAN></DIV>
<P>这样，一个比较棘手的问题用ajax就获得了完美解决，并且不会因向后台回发而导致下拉框初始化，导致选项改变，亲爱的朋友，看了这个例子，你对ajax是不是也有了<BR>更好的认识呢？<BR><BR>&nbsp;<BR></P><img src="http://www.cnblogs.com/ustbwuyi/aggbug/679586.html?type=1" width="1" height="1" alt=""/><p>评论: 7　<a href="http://www.cnblogs.com/ustbwuyi/archive/2007/03/19/679586.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/ustbwuyi/archive/2007/03/19/679586.html#commentform" target="_blank">发表评论</a></p><p><a href="http://job.cnblogs.com/" target="_blank">找优秀程序员，就在博客园</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/59295/" target="_blank">9大IT科技公司总部览</a><span style="color:gray">(2010-03-21 21:00)</span><br/>· <a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><span style="color:gray">(2010-03-21 19:51)</span><br/>· <a href="http://news.cnblogs.com/n/59292/" target="_blank">意大利研发出“移动虚拟校园”技术</a><span style="color:gray">(2010-03-21 19:33)</span><br/>· <a href="http://news.cnblogs.com/n/59291/" target="_blank">如果 Facebook 是一个国家，它将是第三大人口国</a><span style="color:gray">(2010-03-21 17:50)</span><br/>· <a href="http://news.cnblogs.com/n/59290/" target="_blank">德国公司推出Android平板电脑WePad</a><span style="color:gray">(2010-03-21 17:43)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>Ajax的原理和应用(给公司做所的培训)</title><link>http://www.cnblogs.com/ustbwuyi/archive/2007/02/08/645061.html</link><dc:creator>ustbwuyi</dc:creator><author>ustbwuyi</author><pubDate>Thu, 08 Feb 2007 08:31:00 GMT</pubDate><guid>http://www.cnblogs.com/ustbwuyi/archive/2007/02/08/645061.html</guid><description><![CDATA[<p>阅读: 4958 评论: 55 作者: <a href="http://www.cnblogs.com/ustbwuyi/" target="_blank">ustbwuyi</a> 发表于 2007-02-08 16:31 <a href="http://www.cnblogs.com/ustbwuyi/archive/2007/02/08/645061.html" target="_blank">原文链接</a></p><P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在写这篇文章之前，曾经写过一篇关于</SPAN><SPAN lang=EN-US>AJAX</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术的随笔，不过涉及到的方面很窄，对</SPAN><SPAN lang=EN-US>AJAX</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术的背景、原理、优缺点等各个方面都很少涉及</SPAN><SPAN lang=EN-US>null</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。这次写这篇文章的背景是因为公司需要对内部程序员做一个培训。项目经理找到了我，并且征询我培训的主题，考虑到之前</SPAN><SPAN lang=EN-US>Javascript</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>CSS</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等</SPAN><SPAN lang=EN-US>WEB</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">开发技术都已经讲解过了，所以决定针对</SPAN><SPAN lang=EN-US>AJAX</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这一块做一个比较系统的培训，所以这篇文章实际上是一个培训的材料。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在这篇文章中，我将从</SPAN><SPAN lang=EN-US>10</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个方面来对</SPAN><SPAN lang=EN-US>AJAX</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术进行系统的讲解。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术的背景</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不可否认，</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术的流行得益于</SPAN><SPAN lang=EN-US>google</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的大力推广，正是由于</SPAN><SPAN lang=EN-US>google earth</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>google suggest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">以及</SPAN><SPAN lang=EN-US>gmail</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等对</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术的广泛应用，催生了</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的流行。而这也让微软感到无比的尴尬，因为早在</SPAN><SPAN lang=EN-US>97</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">年，微软便已经发明了</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的关键技术，并且在</SPAN><SPAN lang=EN-US>99</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">年</SPAN><SPAN lang=EN-US>IE5</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">推出之时，它便开始支持</SPAN><SPAN lang=EN-US>XmlHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象，并且微软之前已经开始在它的一些产品中应用</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，比如说</SPAN><SPAN lang=EN-US>MSDN</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">网站菜单中的一些应用。遗憾的是，不知道出于什么想法，当时微软发明了</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的核心技术之后，并没有看到它的潜力而加以发展和推广，而是将它搁置起来。对于这一点来说，我个人是觉得非常奇怪的，因为以微软的资源和它的战略眼光来说，应该不会看不到</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术的前景，唯一的解释也许就是因为当时它的主要竞争对手</SPAN><SPAN lang=EN-US>Netscape</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的消失反而使它变得麻痹和迟钝，毕竟巨人也有打盹的时候，比如</SPAN><SPAN lang=EN-US>IBM</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">曾经在对微软战略上的失误。正是这一次的失误，成就了它现在的竞争对手</SPAN><SPAN lang=EN-US>google</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方面的领先地位，而事实上</SPAN><SPAN lang=EN-US>google</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目前在</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术方面的领先是微软所无法达到的，这一点在后面我讲述</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">缺陷的时候也会提到。现在微软也意识到了这个问题，因此它也开始在</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">领域奋起直追，比如说推出它自己的</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">框架</SPAN><SPAN lang=EN-US>atlas</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，并且在</SPAN><SPAN lang=EN-US>.NET2.0</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">也提供了一个用来实现异步回调的接口，即</SPAN><SPAN lang=EN-US>ICallBack</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接口。那么微软为什么对自己在</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方面的落后如此紧张呢？现在就让我们来分析一下</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术后面隐藏的深刻意义。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术的意义</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes"></SPAN></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们在平时的开发中都多多少少的接触或者应用到了</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，谈到</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术的意义，我们关注得最多的毫无疑问是提升用户的体验。但是，如果我们结合将来电脑和互联网的发展趋势，我们会发现</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术在某些方面正好代表了这种趋势。为什么这样说呢？我们知道，自从电脑出现以来，一直是桌面软件占据着绝对主导的地位，但是互联网的出现和成功使这一切开始发生着微妙的变化。相当一部分的人都相信，迟早有一天，数据和电脑软件将会从桌面转移到互联网。也就是说，将来的电脑有可能抛弃笨重的硬盘，而直接从互联网来获取数据和服务，我记得我念大学的时候，有位教授给我们上课的时候，曾经设想过这样一种情景，也许在将来的电脑桌面上，没有任何多余的软件和程序，而仅仅只有一个</SPAN><SPAN lang=EN-US>IE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，虽然现在看起来我们距离这一天还很遥远，并且这其中还有很多的问题需要解决，但是我觉得这个并非梦想，而是迟早将实现的现实。那么，这其中的主要问题就是互联网的连接不稳定，谁也不愿意看着自己的电脑从服务器一点一滴的下载数据，那么，</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是不是解决了这个问题呢，说实话，与其说</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">解决了这个问题，倒不如它只是掩盖了这个问题，它只是在服务器和客户端之间充当了一个缓冲器，让用户误以为服务没有中断。精确的说，</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">并不能提高从服务器端下载数据的速度，而只是使这个等待不那么令人沮丧。但是正是这一点就足以产生巨大的影响和震动，它实际上也对桌面软件产生了巨大的冲击。这一点我用一个例子来说明，我们可以比较一下</SPAN><SPAN lang=EN-US>Outlook Express</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>Gmail</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，前者是典型的桌面软件，后者是</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所实现的</SPAN><SPAN lang=EN-US>B/S</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">模式，实际上后者目前已经在慢慢取代前者了，</SPAN><SPAN lang=EN-US>Gmail</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在收发邮件的时候已经和</SPAN><SPAN lang=EN-US>Outlook Express</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的功能几乎没有差别了，而且它不需要安装客户端程序。这就是为什么微软对</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所带来的冲击有着如此的恐惧心理，并且在它前不久所进行的调查之中，将</SPAN><SPAN lang=EN-US>google</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">看做他们未来十年内的主要竞争对手的主要原因之一。当然，这种变化也并不会将桌面软件全部淘汰，现有的浏览器还没有一个能像</SPAN><SPAN lang=EN-US>PhotoShop</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等桌面程序那样处理复杂的图像。但是我们也不能忽视它带来的影响和冲击。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>3</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、关于</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的名字</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>ajax </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的全称是</SPAN><SPAN lang=EN-US>Asynchronous JavaScript and XML</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，其中，</SPAN><SPAN lang=EN-US>Asynchronous </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是异步的意思，它有别于传统</SPAN><SPAN lang=EN-US>web</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">开发中采用的同步的方式。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>4</o:p></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、关于同步和异步</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">异步传输是面向字符的传输，它的单位是字符；而同步传输是面向比特的传输，它的单位是桢，它传输的时候要求接受方和发送方的时钟是保持一致的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">具体来说，异步传输是将比特分成小组来进行传送。一般每个小组是一个</SPAN><SPAN lang=EN-US>8</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位字符，在每个小组的头部和尾部都有一个开始位和一个停止位，它在传送过程中接收方和发送方的时钟不要求一致，也就是说，发送方可以在任何时刻发送这些小组，而接收方并不知道它什么时候到达。一个最明显的例子就是计算机键盘和主机的通信，按下一个键的同时向主机发送一个</SPAN><SPAN lang=EN-US>8</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比特位的</SPAN><SPAN lang=EN-US>ASCII</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码，键盘可以在任何时刻发送代码，这取决于用户的输入速度，内部的硬件必须能够在任何时刻接收一个键入的字符。这是一个典型的异步传输过程。异步传输存在一个潜在的问题，即接收方并不知道数据会在什么时候到达。在它检测到数据并做出响应之前，第一个比特已经过去了。这就像有人出乎意料地从后面走上来跟你说话，而你没来得及反应过来，漏掉了最前面的几个词。因此，每次异步传输的信息都以一个起始位开头，它通知接收方数据已经到达了，这就给了接收方响应、接收和缓存数据比特的时间；在传输结束时，一个停止位表示该次传输信息的终止。按照惯例，空闲（没有传送数据）的线路实际携带着一个代表二进制</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的信号。步传输的开始位使信号变成</SPAN><SPAN lang=EN-US>0</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，其他的比特位使信号随传输的数据信息而变化。最后，停止位使信号重新变回</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，该信号一直保持到下一个开始位到达。例如在键盘上数字“</SPAN><?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:chmetcnv UnitName="”" SourceValue="1" HasSpace="False" Negative="False" NumberType="1" TCSC="0" w:st="on"><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”</SPAN></st1:chmetcnv><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，按照</SPAN><SPAN lang=EN-US>8</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比特位的扩展</SPAN><SPAN lang=EN-US>ASCII</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">编码，将发送“</SPAN><st1:chmetcnv UnitName="”" SourceValue="110001" HasSpace="False" Negative="False" NumberType="1" TCSC="0" w:st="on"><SPAN lang=EN-US>00110001</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”</SPAN></st1:chmetcnv><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，同时需要在</SPAN><SPAN lang=EN-US>8</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比特位的前面加一个起始位，后面一个停止位。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">同步传输的比特分组要大得多。它不是独立地发送每个字符，每个字符都有自己的开始位和停止位，而是把它们组合起来一起发送。我们将这些组合称为数据帧，或简称为帧。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">　　数据帧的第一部分包含一组同步字符，它是一个独特的比特组合，类似于前面提到的起始位，用于通知接收方一个帧已经到达，但它同时还能确保接收方的采样速度和比特的到达速度保持一致，使收发双方进入同步。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">　　帧的最后一部分是一个帧结束标记。与同步字符一样，它也是一个独特的比特串，类似于前面提到的停止位，用于表示在下一帧开始之前没有别的即将到达的数据了。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">　　同步传输通常要比异步传输快速得多。接收方不必对每个字符进行开始和停止的操作。一旦检测到帧同步字符，它就在接下来的数据到达时接收它们。另外，同步传输的开销也比较少。例如，一个典型的帧可能有</SPAN><SPAN lang=EN-US>500</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">字节（即</SPAN><SPAN lang=EN-US>4000</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比特）的数据，其中可能只包含</SPAN><SPAN lang=EN-US>100</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比特的开销。这时，增加的比特位使传输的比特总数增加</SPAN><SPAN lang=EN-US>2.5%</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，这与异步传输中</SPAN><SPAN lang=EN-US>25 %</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的增值要小得多。随着数据帧中实际数据比特位的增加，开销比特所占的百分比将相应地减少。但是，数据比特位越长，缓存数据所需要的缓冲区也越大，这就限制了一个帧的大小。另外，帧越大，它占据传输媒体的连续时间也越长。在极端的情况下，这将导致其他用户等得太久。<BR></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 了解了同步和异步的概念之后，大家应该对ajax为什么可以提升用户体验应该比较清晰了，它是利用异步请求方式的。打个比方，如果现在你家里所在的小区因某种情况而面临停水，现在有关部门公布了两种方案，一是完全停水8个小时，在这8个小时内完全停水，8个小时后恢复正常。二是不完全停水10&nbsp;</o:p></SPAN>个小时，在这10个小时内水没有完全断，只是流量比原来小了很多，在10个小时后恢复正常流量，那么，如果是你你会选择哪种方式呢？显然是后者。</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>5</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所包含的技术</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">大家都知道</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">并非一种新的技术，而是几种原有技术的结合体。它由下列技术组合而成。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>1.</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用</SPAN><SPAN lang=EN-US>CSS</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>XHTML</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来表示。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>2. </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用</SPAN><SPAN lang=EN-US>DOM</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">模型来交互和动态显示。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>3.</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用</SPAN><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来和服务器进行异步通信。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>4.</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">使用</SPAN><SPAN lang=EN-US>javascript</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来绑定和调用。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在上面几中技术中，除了</SPAN><SPAN lang=EN-US>XmlHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象以外，其它所有的技术都是基于</SPAN><SPAN lang=EN-US>web</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">标准并且已经得到了广泛使用的，</SPAN><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">虽然目前还没有被</SPAN><SPAN lang=EN-US>W<st1:chmetcnv UnitName="C" SourceValue="3" HasSpace="False" Negative="False" NumberType="1" TCSC="0" w:st="on">3C</st1:chmetcnv></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所采纳，但是它已经是一个事实的标准，因为目前几乎所有的主流浏览器都支持它。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>6</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">原理和</SPAN><SPAN lang=EN-US>XmlHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的原理简单来说通过</SPAN><SPAN lang=EN-US>XmlHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象来向服务器发异步请求，从服务器获得数据，然后用</SPAN><SPAN lang=EN-US>javascript</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来操作</SPAN><SPAN lang=EN-US>DOM</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">而更新页面。这其中最关键的一步就是从服务器获得请求数据。要清楚这个过程和原理，我们必须对</SPAN> <SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有所了解。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; mso-char-indent-count: 1.0"><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的核心机制，它是在</SPAN><SPAN lang=EN-US>IE5</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中首先引入的，是一种支持异步请求的技术。简单的说，也就是</SPAN><SPAN lang=EN-US>javascript</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以及时向服务器提出请求和处理响应，而不阻塞用户。达到无刷新的效果。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所以我们先从</SPAN><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">讲起，来看看它的工作原理。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">首先，我们先来看看</SPAN><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个对象的属性。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">它的属性有：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>onreadystatechange<SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">每次状态改变所触发事件的事件处理程序。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>responseText<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">从服务器进程返回数据的字符串形式。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>responseXML<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">从服务器进程返回的</SPAN><SPAN lang=EN-US>DOM</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">兼容的文档数据对象。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>status<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">从服务器返回的数字代码，比如常见的</SPAN><SPAN lang=EN-US>404</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（未找到）和</SPAN><SPAN lang=EN-US>200</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（已就绪）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>status Text<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">伴随状态码的字符串信息</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>readyState<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象状态值</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>0 (</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">未初始化</SPAN><SPAN lang=EN-US>) </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象已建立，但是尚未初始化（尚未调用</SPAN><SPAN lang=EN-US>open</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>1 (</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">初始化</SPAN><SPAN lang=EN-US>) </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象已建立，尚未调用</SPAN><SPAN lang=EN-US>send</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>2 (</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">发送数据</SPAN><SPAN lang=EN-US>) send</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法已调用，但是当前的状态及</SPAN><SPAN lang=EN-US>http</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">头未知</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>3 (</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">数据传送中</SPAN><SPAN lang=EN-US>) </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">已接收部分数据，因为响应及</SPAN><SPAN lang=EN-US>http</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">头不全，这时通过</SPAN><SPAN lang=EN-US>responseBody</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>responseText</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">获取部分数据会出现错误，</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>4 (</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">完成</SPAN><SPAN lang=EN-US>) </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">数据接收完毕</SPAN><SPAN lang=EN-US>,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">此时可以通过通过</SPAN><SPAN lang=EN-US>responseXml</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>responseText</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">获取完整的回应数据</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">但是，由于各浏览器之间存在差异，所以创建一个</SPAN><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象可能需要不同的方法。这个差异主要体现在</SPAN><SPAN lang=EN-US>IE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和其它浏览器之间。下面是一个比较标准的创建</SPAN><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象的方法。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">function</SPAN> CreateXmlHttp()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes">非<SPAN lang=EN-US>IE</SPAN>浏览器创建<SPAN lang=EN-US>XmlHttpRequest</SPAN>对象<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN>(window.XmlHttpRequest)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>xmlhttp=<SPAN style="COLOR: blue">new</SPAN> XmlHttpRequest();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//IE</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes">浏览器创建<SPAN lang=EN-US>XmlHttpRequest</SPAN>对象<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN>(window.ActiveXObject)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">try<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>xmlhttp=<SPAN style="COLOR: blue">new</SPAN> ActiveXObject(<SPAN style="COLOR: maroon">"Microsoft.XMLHTTP"</SPAN>);<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">catch</SPAN>(e)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">try</SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>xmlhttp=<SPAN style="COLOR: blue">new</SPAN> ActiveXObject(<SPAN style="COLOR: maroon">"msxml2.XMLHTTP"</SPAN>);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">catch</SPAN>(ex){}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>}<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes">function</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"> Ustbwuyi()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">var</SPAN> data=document.getElementById(<SPAN style="COLOR: maroon">"username"</SPAN>).value;<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>CreateXmlHttp();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="COLOR: blue">if</SPAN>(!xmlhttp)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>alert(<SPAN style="COLOR: maroon">"</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes">创建<SPAN lang=EN-US>xmlhttp</SPAN>对象异常！<SPAN lang=EN-US>"</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes">);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> <SPAN style="COLOR: blue">false</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>xmlhttp.open(<SPAN style="COLOR: maroon">"POST"</SPAN>,url,<SPAN style="COLOR: blue">false</SPAN>);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>xmlhttp.onreadystatechange=<SPAN style="COLOR: blue">function</SPAN>()<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN>(xmlhttp.readyState==4)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>document.getElementById(<SPAN style="COLOR: maroon">"user1"</SPAN>).innerHTML=<SPAN style="COLOR: maroon">"</SPAN></SPAN><SPAN style="FONT-SIZE: 9pt; COLOR: maroon; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes">数据正在加载<SPAN lang=EN-US>..."</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes">;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN>(xmlhttp.status==200)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>document.write(xmlhttp.responseText);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>} <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>xmlhttp.send(); <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>}</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如上所示，函数首先检查</SPAN><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的整体状态并且保证它已经完成（</SPAN><SPAN lang=EN-US>readyStatus=4</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">），即数据已经发送完毕。然后根据服务器的设定询问请求状态，如果一切已经就绪（</SPAN><SPAN lang=EN-US>status=200</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">），那么就执行下面需要的操作。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对于</SPAN><SPAN lang=EN-US>XmlHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的两个方法，</SPAN><SPAN lang=EN-US>open</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>send</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，其中</SPAN><SPAN lang=EN-US>open</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法指定了：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt"><SPAN lang=EN-US>a</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、向服务器提交数据的类型，即</SPAN><SPAN lang=EN-US>post</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">还是</SPAN><SPAN lang=EN-US>get</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.75pt"><SPAN lang=EN-US>b</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、请求的</SPAN><SPAN lang=EN-US>url</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">地址和传递的参数。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>c</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、传输方式，</SPAN><SPAN lang=EN-US>false</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为同步，</SPAN><SPAN lang=EN-US>true</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为异步。默认为</SPAN><SPAN lang=EN-US>true</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。如果是异步通信方式</SPAN><SPAN lang=EN-US>(true)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，客户机就不等待服务器的响应；如果是同步方式</SPAN><SPAN lang=EN-US>(false)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，客户机就要等到服务器返回消息后才去执行其他操作。我们需要根据实际需要来指定同步方式，在某些页面中，可能会发出多个请求，甚至是有组织有计划有队形大规模的高强度的</SPAN><SPAN lang=EN-US>request</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，而后一个是会覆盖前一个的，这个时候当然要指定同步方式。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Send</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法用来发送请求。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">知道了</SPAN><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的工作流程，我们可以看出，</SPAN><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是完全用来向服务器发出一个请求的，它的作用也局限于此，但它的作用是整个</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">实现的关键，因为</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">无非是两个过程，发出请求和响应请求。并且它完全是一种客户端的技术。而</SPAN><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">正是处理了服务器端和客户端通信的问题所以才会如此的重要。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">现在，我们对</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的原理大概可以有一个了解了。我们可以把服务器端看成一个数据接口，它返回的是一个纯文本流，当然，这个文本流可以是</SPAN><SPAN lang=EN-US>XML</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">格式，可以是</SPAN><SPAN lang=EN-US>Html</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，可以是</SPAN><SPAN lang=EN-US>Javascript</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码，也可以只是一个字符串。这时候，</SPAN><SPAN lang=EN-US>XMLHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">向服务器端请求这个页面，服务器端将文本的结果写入页面，这和普通的</SPAN><SPAN lang=EN-US>web</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">开发流程是一样的，不同的是，客户端在异步获取这个结果后，不是直接显示在页面，而是先由</SPAN><SPAN lang=EN-US>javascript</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来处理，然后再显示在页面。至于现在流行的很多</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">控件，比如</SPAN><SPAN lang=EN-US>magicajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等，可以返回</SPAN><SPAN lang=EN-US>DataSet</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等其它数据类型，只是将这个过程封装了的结果，本质上他们并没有什么太大的区别。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>7</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的优点</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>Ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的给我们带来的好处大家基本上都深有体会，在这里我只简单的讲几点：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、最大的一点是页面无刷新，在页面内与服务器通信，给用户的体验非常好。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">　</SPAN><SPAN lang=EN-US> 2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、使用异步方式与服务器通信，不需要打断用户的操作，具有更加迅速的响应能力。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">　</SPAN><SPAN lang=EN-US> 3</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、可以把以前一些服务器负担的工作转嫁到客户端，利用客户端闲置的能力来处理，减轻服务器和带宽的负担，节约空间和宽带租用成本。并且减轻服务器的负担，</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的原则是</SPAN><SPAN lang=EN-US>“</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">按需取数据</SPAN><SPAN lang=EN-US>”</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，可以最大程度的减少冗余请求，和响应对服务器造成的负担。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>4</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、基于标准化的并被广泛支持的技术，不需要下载插件或者小程序。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>8</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的缺点</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下面我着重讲一讲</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的缺陷，因为平时我们大多注意的都是</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">给我们所带来的好处诸如用户体验的提升。而对</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所带来的缺陷有所忽视。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下面所阐述的</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的缺陷都是它先天所产生的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">干掉了</SPAN><SPAN lang=EN-US>back</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">按钮，即对浏览器后退机制的破坏。后退按钮是一个标准的</SPAN><SPAN lang=EN-US>web</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">站点的重要功能，但是它没法和</SPAN><SPAN lang=EN-US>js</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">进行很好的合作。这是</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所带来的一个比较严重的问题，因为用户往往是希望能够通过后退来取消前一次操作的。那么对于这个问题有没有办法？答案是肯定的，用过</SPAN><SPAN lang=EN-US>Gmail</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的知道，</SPAN><SPAN lang=EN-US>Gmail</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下面采用的</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术解决了这个问题，在</SPAN><SPAN lang=EN-US>Gmail</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下面是可以后退的，但是，它也并不能改变</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的机制，它只是采用的一个比较笨但是有效的办法，即用户单击后退按钮访问历史记录时，通过创建或使用一个隐藏的</SPAN><SPAN lang=EN-US>IFRAME</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来重现页面上的变更。（例如，当用户在</SPAN><SPAN lang=EN-US>Google Maps</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中单击后退时，它在一个隐藏的</SPAN><SPAN lang=EN-US>IFRAME</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中进行搜索，然后将搜索结果反映到</SPAN><SPAN lang=EN-US>Ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">元素上，以便将应用程序状态恢复到当时的状态。）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">但是，虽然说这个问题是可以解决的，但是它所带来的开发成本是非常高的，和</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">框架所要求的快速开发是相背离的。这是</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所带来的一个非常严重的问题。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、安全问题</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术同时也对</SPAN><SPAN lang=EN-US>IT</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">企业带来了新的安全威胁，</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术就如同对企业数据建立了一个直接通道。这使得开发者在不经意间会暴露比以前更多的数据和服务器逻辑。</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的逻辑可以对客户端的安全扫描技术隐藏起来，允许黑客从远端服务器上建立新的攻击。还有</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">也难以避免一些已知的安全弱点，诸如跨站点脚步攻击、</SPAN><SPAN lang=EN-US>SQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">注入攻击和基于</SPAN><SPAN lang=EN-US>credentials</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的安全漏洞等。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>3</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、对搜索引擎的支持比较弱。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>4</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、破坏了程序的异常机制。至少从目前看来，像</SPAN><SPAN lang=EN-US>ajax.dll</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>ajaxpro.dll</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这些</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">框架是会破坏程序的异常机制的。关于这个问题，我曾经在开发过程中遇到过，但是查了一下网上几乎没有相关的介绍。后来我自己做了一次试验，分别采用</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和传统的</SPAN><SPAN lang=EN-US>form</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提交的模式来删除一条数据</SPAN><SPAN lang=EN-US>……</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">给我们的调试带来了很大的困难。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>5</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、另外，像其他方面的一些问题，比如说违背了</SPAN><SPAN lang=EN-US>url</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和资源定位的初衷。例如，我给你一个</SPAN><SPAN lang=EN-US>url</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">地址，如果采用了</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术，也许你在该</SPAN><SPAN lang=EN-US>url</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">地址下面看到的和我在这个</SPAN><SPAN lang=EN-US>url</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">地址下看到的内容是不同的。这个和资源定位的初衷是相背离的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>6</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、一些手持设备（如手机、</SPAN><SPAN lang=EN-US>PDA</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等）现在还不能很好的支持</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，比如说我们在手机的浏览器上打开采用</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">技术的网站时，它目前是不支持的，当然，这个问题和我们没太多关系。</SPAN><SPAN lang=EN-US> </SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>9</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的几种框架</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目前我们采用的比较多的</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">框架主要有</SPAN><SPAN lang=EN-US>ajax.dll,ajaxpro.dll,magicajax.dll </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">以及微软的</SPAN><SPAN lang=EN-US>atlas</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">框架。</SPAN><SPAN lang=EN-US>Ajax.dll</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>Ajaxpro.dll</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这两个框架差别不大，而</SPAN><SPAN lang=EN-US>magicajax.dll</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">只是封装得更厉害一些，比如说它可以直接返回</SPAN><SPAN lang=EN-US>DataSet</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">数据集，前面我们已经说过，</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">返回的都是字符串，</SPAN><SPAN lang=EN-US>magicajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">只是对它进行了封装而已。但是它的这个特点可以给我们带来很大的方便，比如说我们的页面有一个列表，而列表的数据是不断变化的，那么我们可以采用</SPAN><SPAN lang=EN-US>magicajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来处理，操作很简单，添加</SPAN><SPAN lang=EN-US>magicajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">之后，将要更新的列表控件放在</SPAN><SPAN lang=EN-US>magicajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的控件之内，然后在</SPAN><SPAN lang=EN-US>pageload</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里面定义更新间隔的时间就</SPAN><SPAN lang=EN-US>ok</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">了，</SPAN><SPAN lang=EN-US>atlas</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的原理和</SPAN><SPAN lang=EN-US>magicajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">差不多。但是，需要注意的一个问题是，这几种框架都只支持</SPAN><SPAN lang=EN-US>IE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，没有进行浏览器兼容方面的处理，用反编译工具察看他们的代码就可以知道。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">除了这几种框架之外，我们平时用到的比较多的方式是自己创建</SPAN><SPAN lang=EN-US>xmlHttpRequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象，这种方式和前面的几种框架相比更具有灵活性。另外，在这里还提一下</SPAN><SPAN lang=EN-US>aspnet2.0</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">自带的异步回调接口，它和</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一样也可以实现局部的无刷新，但它的实现实际上也是基于</SPAN><SPAN lang=EN-US>xmlhttprequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象的，另外也是只支持</SPAN><SPAN lang=EN-US>IE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，当然这是微软的一个竞争策略。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>10</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN lang=EN-US>ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">示例</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">验证用户名是否注册。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">采用两种方式</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>1 ajax.dll</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>2 </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">自己写</SPAN><SPAN lang=EN-US>xmlhttprequest</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>10.ajax</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中常见到的一些错误</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>1 </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">配置的问题</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US>pageload</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里面配置该页面的时候</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>11</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在后台调用的方法里调用了前台的部分</SPAN><SPAN lang=EN-US>…</SPAN></P>
<P><FONT face=宋体>　</FONT></P><img src="http://www.cnblogs.com/ustbwuyi/aggbug/645061.html?type=1" width="1" height="1" alt=""/><p>评论: 55　<a href="http://www.cnblogs.com/ustbwuyi/archive/2007/02/08/645061.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/ustbwuyi/archive/2007/02/08/645061.html#commentform" target="_blank">发表评论</a></p><p><a href="http://job.cnblogs.com/" target="_blank">找优秀程序员，就在博客园</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/59295/" target="_blank">9大IT科技公司总部览</a><span style="color:gray">(2010-03-21 21:00)</span><br/>· <a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><span style="color:gray">(2010-03-21 19:51)</span><br/>· <a href="http://news.cnblogs.com/n/59292/" target="_blank">意大利研发出“移动虚拟校园”技术</a><span style="color:gray">(2010-03-21 19:33)</span><br/>· <a href="http://news.cnblogs.com/n/59291/" target="_blank">如果 Facebook 是一个国家，它将是第三大人口国</a><span style="color:gray">(2010-03-21 17:50)</span><br/>· <a href="http://news.cnblogs.com/n/59290/" target="_blank">德国公司推出Android平板电脑WePad</a><span style="color:gray">(2010-03-21 17:43)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>最近遇到的几个小问题总结</title><link>http://www.cnblogs.com/ustbwuyi/archive/2007/01/30/634934.html</link><dc:creator>ustbwuyi</dc:creator><author>ustbwuyi</author><pubDate>Tue, 30 Jan 2007 09:25:00 GMT</pubDate><guid>http://www.cnblogs.com/ustbwuyi/archive/2007/01/30/634934.html</guid><description><![CDATA[<p>阅读: 436 评论: 1 作者: <a href="http://www.cnblogs.com/ustbwuyi/" target="_blank">ustbwuyi</a> 发表于 2007-01-30 17:25 <a href="http://www.cnblogs.com/ustbwuyi/archive/2007/01/30/634934.html" target="_blank">原文链接</a></p>1 、文件上传<BR><BR>最近做广告发布系统，不可避免的遇到上传图片文件的问题。基本原理是将图片上传到服务器，然后将它的路径保存在数据库，显示的时候从服务器取出该路径，让img直接指向这个路径即可。当然在上传的时候需要判断文件类型，比如是jpg、gif，swf等。在这里我是用正则表达式来验证的，该方法非常有效，而直接用endwith方法来判断有时候会出现一些莫名其妙的问题。<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">获取上传文件的路径</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;filename</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.file1.PostedFile.FileName;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">定义正则表达式</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Regex&nbsp;reg&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Regex(</SPAN><SPAN style="COLOR: #000000">@"</SPAN><SPAN style="COLOR: #000000">^.+\.(jpg)|(gif)|(swf)|(jpeg)$</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">用正则表达式来判定</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">!</SPAN><SPAN style="COLOR: #000000">reg.Match(filename.ToLower()).Success)<BR><IMG id=Codehighlighter1_224_259_Open_Image onclick="this.style.display='none'; Codehighlighter1_224_259_Open_Text.style.display='none'; Codehighlighter1_224_259_Closed_Image.style.display='inline'; Codehighlighter1_224_259_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_224_259_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_224_259_Closed_Text.style.display='none'; Codehighlighter1_224_259_Open_Image.style.display='inline'; Codehighlighter1_224_259_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_224_259_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_224_259_Open_Text><SPAN style="COLOR: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">base</SPAN><SPAN style="COLOR: #000000">.Alert(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">上传的文件类型不符合要求！</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">获取上传文件的名称</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;name&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;DateTime.Now.ToString("yyyyMMddhhmmss")+filename.Substring(filename.LastIndexOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"><A href='file://\\")+1'>\\</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</A></SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">要上传的服务器地址</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;path</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">Server.MapPath(</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">.Format(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">~/AdFiles/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">))</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">name;<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_453_503_Open_Image onclick="this.style.display='none'; Codehighlighter1_453_503_Open_Text.style.display='none'; Codehighlighter1_453_503_Closed_Image.style.display='inline'; Codehighlighter1_453_503_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_453_503_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_453_503_Closed_Text.style.display='none'; Codehighlighter1_453_503_Open_Image.style.display='inline'; Codehighlighter1_453_503_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_453_503_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_453_503_Open_Text><SPAN style="COLOR: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.file1.PostedFile.SaveAs(path);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(Exception&nbsp;ee)<BR><IMG id=Codehighlighter1_537_589_Open_Image onclick="this.style.display='none'; Codehighlighter1_537_589_Open_Text.style.display='none'; Codehighlighter1_537_589_Closed_Image.style.display='inline'; Codehighlighter1_537_589_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_537_589_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_537_589_Closed_Text.style.display='none'; Codehighlighter1_537_589_Open_Image.style.display='inline'; Codehighlighter1_537_589_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_537_589_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/Images/dot.gif"></SPAN><SPAN id=Codehighlighter1_537_589_Open_Text><SPAN style="COLOR: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">base</SPAN><SPAN style="COLOR: #000000">.Alert(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">图片上传失败，请与服务器空间商联系确认权限！</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN></DIV><BR>其次是上传权限的设置，如果是在本地，需要对虚拟目录下该文件夹设置写入权限，在该目录上鼠标右键-&gt;属性-&gt;安全-&gt;everyone-&gt;写入即可。<BR>如果是在服务器，除了需要有该文件夹的写入权限之外，还要在web.config里面设置一下。<BR><BR><FONT face=Verdana>在system.web节点里面添加如下代码：<BR>&lt;identity impersonate="true" userName="UserName" password="PassWord" /&gt;</FONT><BR><img src="http://www.cnblogs.com/ustbwuyi/aggbug/634934.html?type=1" width="1" height="1" alt=""/><p>评论: 1　<a href="http://www.cnblogs.com/ustbwuyi/archive/2007/01/30/634934.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/ustbwuyi/archive/2007/01/30/634934.html#commentform" target="_blank">发表评论</a></p><p><a href="http://job.cnblogs.com/" target="_blank">找优秀程序员，就在博客园</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/59295/" target="_blank">9大IT科技公司总部览</a><span style="color:gray">(2010-03-21 21:00)</span><br/>· <a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><span style="color:gray">(2010-03-21 19:51)</span><br/>· <a href="http://news.cnblogs.com/n/59292/" target="_blank">意大利研发出“移动虚拟校园”技术</a><span style="color:gray">(2010-03-21 19:33)</span><br/>· <a href="http://news.cnblogs.com/n/59291/" target="_blank">如果 Facebook 是一个国家，它将是第三大人口国</a><span style="color:gray">(2010-03-21 17:50)</span><br/>· <a href="http://news.cnblogs.com/n/59290/" target="_blank">德国公司推出Android平板电脑WePad</a><span style="color:gray">(2010-03-21 17:43)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>javascript中事件的理解</title><link>http://www.cnblogs.com/ustbwuyi/archive/2006/10/23/537313.html</link><dc:creator>ustbwuyi</dc:creator><author>ustbwuyi</author><pubDate>Mon, 23 Oct 2006 07:22:00 GMT</pubDate><guid>http://www.cnblogs.com/ustbwuyi/archive/2006/10/23/537313.html</guid><description><![CDATA[<p>阅读: 635 评论: 0 作者: <a href="http://www.cnblogs.com/ustbwuyi/" target="_blank">ustbwuyi</a> 发表于 2006-10-23 15:22 <a href="http://www.cnblogs.com/ustbwuyi/archive/2006/10/23/537313.html" target="_blank">原文链接</a></p>&nbsp;在javascript中，event事件是一个必不可少的讨论话题，它在和用户的交互中起到了很重要的作用。今天我们就来讨论一下JavaScript中的事件处理，并且结合它来阐叙Ajax框架实现拖动效果的原理了。<br>一、 Event对象<br>&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;Event对象的主要属性和方法<br>　　event代表事件的状态，专门负责对事件的处理，它的属性和方法能帮助我们完成很多和用户交互的操作，下面我们就来看看它的一些属性和方法。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type：事件的类型，就是HTML标签属性中，没有&#8220;on&#8221;前缀之后的字符串，例如&#8220;Click&#8221;就代表单击事件。<br><br>　　srcElement：事件源，就是发生事件的元素。比如&lt;a onclick="check()"&gt;&lt;/a&gt; a这个链接是事件发生的源头，也就是该事件的srcElement。<br><br>　　button：声明了被按下的鼠标键，是一个整数。0代表没有按键，1代表鼠标左键，2代表鼠标右键，4代表鼠标的中间键，如果按下了多个鼠标键，就把这些值加在一起，所以3就代表左右键同时按下。<br><br>　　clientX/clientY：是指事件发生的时候，鼠标的横、纵坐标，返回的是整数，它们的值是相对于包容窗口的左上角生成的。<br><br>　　offsetX/offsetY：鼠标指针相对于源元素的位置，可以确定单击Image对象的哪个象素。<br><br>　　altKey，ctrlKey，shiftKey：顾名思义，这些属性是指鼠标事件发生的时候，是否同时按住了Alt、Ctrl或者Shift键，返回的是一个布尔值。<br><br>　　keyCode：返回keydown和keyup事件发生的时候，按键的代码以及keypress事件的Unicode字符。比如event.keyCode=13代表按下了回车键；<br><br>　　fromElement、toElement前者是指代mouseover事件移动过的文档元素，后者指代mouseout事件中鼠标移动到的文档元素。<br><br>　　cancelBubble：一个布尔属性，把它设置为true的时候，将停止事件进一步起泡到包容层次的元素，它用于检测是否接受上层元素的事件的控制。true代表不被上层元素的事件控制，false代表允许被上层元素的事件控制。<br><br>　　returnValue：一个布尔值属性，设置为false的时候可以阻止浏览器执行默认的事件动作，相当于&lt;a href=&#8221;#&#8221; onclick=&#8221;ProcessMethod();return false;&#8221; /&gt;。<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attachEvent()和detachEvent()方法：为制定DOM对象事件类型注册多个事件处理函数的方法，它们有两个参数，第一个是事件类型，第二个是事件处理函数。在attachEvent()事件执行的时候，this关键字指向的是window对象，而不是发生事件的那个元素。<br><br>&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;IE Event对象的一些说明<br>　　Event对象是一个全局属性<br>　　在IE中，不能把Event对象作为参数传递给事件处理程序，只能用window.event或者event来引用Event对象。因为在IE中，Event是window的一个属性，也就是说event是一个全局变量，这个变量提供了事件的细节。<br>&nbsp;3 关于事件的起泡的概念 <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IE中事件的起泡：IE中事件可以沿着包容层次一点点起泡到上层，也就是说，下层的DOM节点定义的事件处理函数，到了上层的节点如果还有和下层相同事件类型的事件处理函数，那么上层的事件处理函数也会执行。例如，&lt;div&gt;标签包含了&lt;a&gt;，如果这两个标签都有 onclick事件的处理函数，那么执行的情况就是先执行&lt;a&gt;标签的onclick事件处理函数，再执行&lt;div&gt;的事件处理函数。如果希望&lt;a&gt;的事件处理函数执行完毕之后，不希望执行上层的&lt;div&gt;的onclick的事件处理函数了，那么就把 cancelBubble设置为false即可。<br>　　<br>二、 IE中拖动DOM元素的例子<br>/*<br>&nbsp; 该函数由mousedown事件处理调用<br>&nbsp; 它为随后发生的mousemove和mouseup事件注册了临时的捕捉事件处理程序<br>&nbsp; 并用这些事件处理程序拖动指定的文档元素<br>&nbsp; 第二个参数必须是mousedown事件的事件对象<br>*/<br>function beginDrag(elementToDrag,event)<br>{<br>&nbsp; //该元素当前位于何处<br>&nbsp; //该元素的样式性质必须具有left和top css属性<br>&nbsp; //此外，我们假定他们用象素做单位<br>&nbsp; //var x=parseInt(elementToDrag.style.left);<br>&nbsp; //var y=parseInt(elementToDrag.style.top);<br>&nbsp; <br>&nbsp; //计算一个点和鼠标点击之间的距离，下面的嵌套的moveHandler函数需要这些值<br>&nbsp; var deltaX=event.clientX-parseInt(elementToDrag.style.left);<br>&nbsp; var deltaY=event.clientY-parseInt(elementToDrag.style.top);<br>&nbsp; <br>//&nbsp; 注册mousedown事件后发生的mousemove和mouseup事件的处理程序<br>//&nbsp; 注意，它们被注册为文档的捕捉事件处理程序<br>//&nbsp; 在鼠标按钮保持按下的状态的时候，这些事件处理程序保持活动的状态<br>//&nbsp; 在按钮被释放的时候，它们被删除<br>&nbsp; document.attachEvent("onmousemove",moveHandler);<br>&nbsp; document.attachEvent("onmouseup",upHandler);<br>&nbsp;&nbsp; <br>&nbsp; //我们已经处理了该事件，不要让别的元素看到它<br>&nbsp;event.cancelBubble=true;<br>&nbsp;event.returnValue=false;<br>&nbsp; <br>&nbsp; /*<br>&nbsp;&nbsp;&nbsp; 这是在元素被拖动时候捕捉mousemove事件的处理程序，它响应移动的元素<br>&nbsp;&nbsp;&nbsp; <br>&nbsp; */<br>&nbsp; function moveHandler(e)&nbsp; <br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; //把元素移动到当前的鼠标位置<br>&nbsp;&nbsp;&nbsp; e=window.event;<br>&nbsp;&nbsp;&nbsp; elementToDrag.style.left=(event.clientX-deltaX)+"px";<br>&nbsp;&nbsp;&nbsp; elementToDrag.style.top=(event.clientY-deltaY)+"px";<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //不要让别的元素看到该事件<br>&nbsp;&nbsp;&nbsp; event.cancelBubble=true;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp; }<br>&nbsp; <br>&nbsp; /*<br>&nbsp;&nbsp;&nbsp; 该事件将捕捉拖动结束的时候发生的mouseup事件<br>&nbsp; */<br>&nbsp; function upHandler(e)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; //注销事件处理程序<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.detachEvent("onmouseup",upHandler);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.detachEvent("onmousemove",moveHandler);}<br>&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; event.cancelBubble=true;<br>&nbsp;&nbsp;&nbsp; }&nbsp; <br>&nbsp;&nbsp; 调用它的HTML文件代码：<br>　&lt;html&gt;<br>　&lt;head&gt;<br>　&nbsp;&nbsp;&nbsp; &lt;title&gt;Untitled Page&lt;/title&gt;<br>　&nbsp;&nbsp;&nbsp; &lt;script type="text/javascript" src="dragIE.js"&gt;&lt;/script&gt;<br>　&lt;/head&gt;<br>　&lt;body&gt;<br>　&lt;div style="position:absolute;left:100px;top:100px;background-color:White;border:solid black;"&gt;<br>　&nbsp; &lt;div style="background-color:Gray;border-bottom:solid black;padding:3px;font-family:Sans-Serif;font-weight:bold;" onmousedown="beginDrag(this.parentNode,event);"&gt;<br>　&nbsp; 拖动我&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;<br>　&nbsp; &lt;/div&gt;<br>　&nbsp; &lt;div&gt;<br>　&nbsp; &lt;p&gt;This is a test.Testing,testing&lt;/p&gt;&lt;/div&gt;<br>　&lt;/div&gt;<br>　&lt;/body&gt;<br>三、 DOM中的高级事件处理<br>&nbsp;IE 6中的事件处理，并不是W3C DOM标准的事件处理模型，所以如果上述代码运行在Mozilla Firefox的浏览器中，就会失去作用，同时即将发布的IE 7也将支持W3C DOM的二级标准，所以掌握DOM的高级事件处理显得就很重要了，因为W3C DOM二级标准是未来Web的发展方向，同时W3C DOM的API非常常用，为未来更加复杂的Web开发提供了良好的基础。<br>（一）事件处理程序的作用域和事件的传播<br>　　在正式讨论DOM高级事件处理之前，我们有必要了解一下事件处理程序的作用域。事件处理程序的作用域要比普通的函数作用域复杂很多。普通的函数作用域链比较容易，例如在一个普通函数中查找一个变量a，那么JavaScript解释器会先在该函数的调用对象中查找是否有a这个变量，如果没有，将会在作用域链的下一个对象，一般是全局对象中查找。但是事件处理程序没这么简单，特别是用HTML的属性定义的，它们的作用域链的头部是调用它们的对象，而下一个对象并不是全局对象，而是触发事件处理程序的对象。这样就会出现一个问题，window和document都有一个方法open()，如果open()前面不加修饰，那么在事件处理的函数中将会调用document.open()方法，而不是常用的window.open()方法，所以使用的时候应该明确指明是 window.open()。<br>（二）事件传播和注册事件处理程序<br>1.事件传播<br>　　在二级DOM标准中，事件处理程序比较复杂，当事件发生的时候，目标节点的事件处理程序就会被触发执行，但是目标节点的父节点也有机会来处理这个事件。事件的传播分为三个阶段，首先是捕捉阶段，事件从 Document对象沿着DOM树向下传播到目标节点，如果目标的任何一个父节点注册了捕捉事件的处理程序，那么事件在传播的过程中就会首先运行这个程序。下一个阶段就是发生在目标节点自身了，注册在目标节点上的相应的事件处理程序就会执行；最后是起泡阶段，事件将从目标节点向上传回给父节点，同样，如果父节点有相应的事件处理程序也会处理。在IE中，没有捕捉的阶段，但是有起泡的阶段。可以用stopPropagating()方法来停止事件传播，也就是让其他元素对这个事件不可见，在IE 6中，就是把cancelBubble设置为true。<br>2.注册事件处理程序<br>　　和IE一样， DOM标准也有自己的事件处理程序，不过DOM二级标准的事件处理程序比IE的强大一些，事件处理程序的注册用addEventListner方法，该方法有三个参数，第一个是事件类型，第二个是处理的函数，第三个是一个布尔值，true表示制定的事件处理程序将在事件传播的阶段用于捕捉事件，否则就不捕捉，当事件发生在对象上才触发执行这个事件处理的函数，或者发生在该对象的字节点上，并且向上起泡到这个对象上的时候，触发执行这个事件处理的函数。例如：document.addEventListener("mousemove",moveHandler,true);就是在mousemove事件发生的时候，调用moveHandler函数，并且可以捕捉事件。<br>　　可以用addEventListener为一个事件注册多个事件处理的程序，但是这些函数的执行顺序是不确定，并不像C#那样按照注册的顺序执行。<br>在Mozilla Firefox中用addEventListener注册一个事件处理程序的时候，this关键字就表示调用事件处理程序的文档元素，但是其他浏览器并不一定是这样，因为这不是DOM标准，正确的做法是用currentTarget属性来引用调用事件处理程序的文档元素。<br>3.二级DOM标准中的Event<br>和IE不同的是，W3C DOM中的Event对象并不是window全局对象下面的属性，换句话说，event不是全局变量。通常在DOM二级标准中，event作为发生事件的文档对象的属性。Event含有两个子接口，分别是UIEvent和MutationEvent，这两个子接口实现了Event的所有方法和属性，而 MouseEvent接口又是UIEvent的子接口，所以实现了UIEvent和Event的所有方法和属性。下面，我们就看看Event、 UIEvent和MouseEvent的主要属性和方法。<br>　　1.Event<br>　　&nbsp; type：事件类型，和IE类似，但是没有&#8220;on&#8221;前缀，例如单击事件只是&#8220;click&#8221;。<br>　　&nbsp; target：发生事件的节点。<br>　　&nbsp; currentTarget：发生当前正在处理的事件的节点，可能是Target属性所指向的节点，也可能由于捕捉或者起泡，指向Target所指节点的父节点。<br>　　&nbsp; eventPhase：指定了事件传播的阶段。是一个数字。<br>　　&nbsp; timeStamp：事件发生的时间。<br>　　&nbsp; bubbles：指明该事件是否起泡。<br>　　&nbsp; cancelable：指明该事件是否可以用preventDefault()方法来取消默认的动作。<br>　　&nbsp; preventDefault()方法：取消事件的默认动作；<br>　　&nbsp; stopPropagation()方法：停止事件传播。<br>　　2.UIEvent<br>　　&nbsp; view：发生事件的window对象。<br>　　&nbsp; detail：提供事件的额外信息，对于单击事件、mousedown和mouseup事件都代表的是点击次数。<br>　　3.MouseEvent<br>　　　button：一个数字，指明在mousedown、mouseup和单击事件中，鼠标键的状态，和IE中的button属性类似，但是数字代表的意义不一样，0代表左键，1代表中间键，2代表右键。<br>　　　altKey、ctrlKey、shiftKey、metaKey：和IE相同，但是IE没有最后一个。<br>clientX、clientY：和IE的含义相同，但是在DOM标准中，这两个属性值都不考虑文档的滚动情况，也就是说，无论文档滚动到哪里，只要事件发生在窗口左上角，clientX和clientY都是0，所以在IE中，要想得到事件发生的坐标相对于文档开头的位置，要加上 document.body.scrollLeft和document.body.scrollTop。<br>　　　screenX、screenY：鼠标指针相对于显示器左上角的位置，如果你想打开新的窗口，这两个属性很重要。<br>　　　relatedTarget：和IE中的fromElement、toElement类似，除了对于mouseover和mouseout有意义外，其他的事件没什么意义。<br>（三）兼容于两种主流浏览器的拖动DOM元素的例子<br>　　好了，刚才讲了这么多DOM编程和IE中的事件，那么如何编写兼容IE和Mozilla Firefox两种主流浏览器的拖拽程序呢？代码如下：<br>function beginDrag(elementToDrag,event)<br>{<br>&nbsp; var deltaX=event.clientX-parseInt(elementToDrag.style.left);<br>&nbsp; var deltaY=event.clientY-parseInt(elementToDrag.style.top);<br>&nbsp; <br>if(document.addEventListener) <br>{<br>&nbsp; document.addEventListener("mousemove",moveHandler,true);<br>&nbsp; document.addEventListener("mouseup",upHandler,true);<br>}<br>else if(document.attachEvent)<br>{<br>&nbsp; document.attachEvent("onmousemove",moveHandler);<br>&nbsp; document.attachEvent("onmouseup",upHandler);<br>&nbsp; <br>}<br>&nbsp; <br>&nbsp; if(event.stopPropagation)&nbsp;&nbsp; event.stopPropagation();<br>&nbsp; else event.cancelBubble=true;<br>&nbsp; if(event.preventDefault)&nbsp; event.preventDefault();<br>&nbsp; else event.returnValue=false;<br>&nbsp; <br>&nbsp; function moveHandler(e)&nbsp; <br>&nbsp; {<br>　　if (!e) e=window.event; //如果是IE的事件对象，那么就用window.event<br>　　//全局属性，否则就用DOM二级标准的Event对象。<br>&nbsp;&nbsp;&nbsp; elementToDrag.style.left=(event.clientX-deltaX)+"px";<br>&nbsp;&nbsp;&nbsp; elementToDrag.style.top=(event.clientY-deltaY)+"px";<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; if(event.stopPropagation)&nbsp;&nbsp; event.stopPropagation();<br>&nbsp;&nbsp;&nbsp; else event.cancelBubble=true;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp; }<br>&nbsp; <br>&nbsp; function upHandler(e)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(document.removeEventListener)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.removeEventListener("mouseup",upHandler,true);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.removeEventListener("mousemove",moveHandler,true);}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.detachEvent("onmouseup",upHandler);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.detachEvent("onmousemove",moveHandler);}<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(event.stopPropagation)&nbsp;&nbsp; event.stopPropagation();<br>&nbsp;&nbsp;&nbsp; else event.cancelBubble=true;<br>&nbsp;&nbsp;&nbsp; <br>最后我们来回顾一下事件执行过程中的三个阶段：<br><span id=ctl00_Ajaxpanel3$RBS_Holder><span id=ctl00_Ajaxpanel3 ajaxcall="async"><span id=ctl00_managerContentPlaceHolder_webPartManager_wp1244878837_ctl00_DataList_ctl02_Description><font size=3><span lang=EN-US><font face="Times New Roman">&nbsp;1 捕捉阶段，事件从Document对象沿Dom解析的树向下传播给目标节点。<br></font></span></font>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><font size=3><span lang=EN-US><font face="Times New Roman">&nbsp;2 目标节点触发阶段 事件处理程序在目标上的运行阶段&nbsp;<br></font></span><span lang=EN-US><font face="Times New Roman">&nbsp;3 起泡阶段 事件从目标元素向上传播或者起泡回Document对象的文档层次。<br>&nbsp;</font></span></font></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><o:p><font face="Times new roman" size=3>&nbsp;</font></o:p></span></p>
</span></span></span><br>
<img src="http://www.cnblogs.com/ustbwuyi/aggbug/537313.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/ustbwuyi/archive/2006/10/23/537313.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/ustbwuyi/archive/2006/10/23/537313.html#commentform" target="_blank">发表评论</a></p><p><a href="http://job.cnblogs.com/" target="_blank">找优秀程序员，就在博客园</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/59295/" target="_blank">9大IT科技公司总部览</a><span style="color:gray">(2010-03-21 21:00)</span><br/>· <a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><span style="color:gray">(2010-03-21 19:51)</span><br/>· <a href="http://news.cnblogs.com/n/59292/" target="_blank">意大利研发出“移动虚拟校园”技术</a><span style="color:gray">(2010-03-21 19:33)</span><br/>· <a href="http://news.cnblogs.com/n/59291/" target="_blank">如果 Facebook 是一个国家，它将是第三大人口国</a><span style="color:gray">(2010-03-21 17:50)</span><br/>· <a href="http://news.cnblogs.com/n/59290/" target="_blank">德国公司推出Android平板电脑WePad</a><span style="color:gray">(2010-03-21 17:43)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>ajax的原理和运行机制</title><link>http://www.cnblogs.com/ustbwuyi/archive/2006/09/28/517233.html</link><dc:creator>ustbwuyi</dc:creator><author>ustbwuyi</author><pubDate>Thu, 28 Sep 2006 06:42:00 GMT</pubDate><guid>http://www.cnblogs.com/ustbwuyi/archive/2006/09/28/517233.html</guid><description><![CDATA[<p>阅读: 1059 评论: 2 作者: <a href="http://www.cnblogs.com/ustbwuyi/" target="_blank">ustbwuyi</a> 发表于 2006-09-28 14:42 <a href="http://www.cnblogs.com/ustbwuyi/archive/2006/09/28/517233.html" target="_blank">原文链接</a></p>关于ajax，是最近炒得非常火的一种技术，并且时下它也是非常流行。当然，它并不是什么新技术，而是在各种已有的技术和支持机制下的一个统一。在我的项目中，偶尔也会用到ajax，用来给用户一些无刷新的体验。用过几次之后，我个人决定对它的原理和运行机制做一个总结。<br>&nbsp;&nbsp;&nbsp; ajax这个名字据说是Asynchronous JavaScript + XML的简写，实际上，它由下列几种技术组合而成。<br><br>&nbsp;&nbsp; 1.使用CSS和XHTML来表示。<br>&nbsp;&nbsp; 2. 使用DOM模型来交互和动态显示。<br>&nbsp;&nbsp;&nbsp;3.使用XMLHttpRequest来和服务器进行异步通信。<br>&nbsp;&nbsp; 4.使用javascript来绑定和调用。<br><br>ajax的原理<br>&nbsp; XMLHttpRequest是ajax的核心机制，它是在IE5中首先引入的，是一种支持异步请求的技术。简单的说，也就是javascript可以及时向服务器提出请求和处理响应，而不阻塞用户。达到无刷新的效果。<br>&nbsp; 所以我们先从XMLHttpRequest讲起，来看看它的工作原理。<br>&nbsp; 首先，我们先来看看XMLHttpRequest这个对象的属性。<br>&nbsp; 它的属性有：<br>&nbsp; onreadystatechange&nbsp; 每次状态改变所触发事件的事件处理程序。<br>&nbsp; responseText&nbsp;&nbsp;&nbsp;&nbsp; 从服务器进程返回数据的字符串形式。<br>&nbsp; responseXML&nbsp;&nbsp; 从服务器进程返回的DOM兼容的文档数据对象。<br>&nbsp; status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 从服务器返回的数字代码，比如常见的404（未找到）和200（已就绪）<br>&nbsp; status Text&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;伴随状态码的字符串信息<br>&nbsp; readyState&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 对象状态值，0—未初始化 1—正在加载&nbsp; 2—加载完毕 3—交互&nbsp;4—完成。<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;但是，由于各浏览器之间存在差异，所以创建一个XMLHttpRequest对象可能需要不同的方法。这个差异主要体现在IE和其它浏览器之间。<br>下面是面对不同浏览器分别创建的XMLHttpRequest对象。<br><br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">script&nbsp;language</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">javascript</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;type</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">text/javascript</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000">&nbsp;xmlHttp&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">创建面向IE的XMLHttpRequest对象</span><span style="COLOR: #008000"><br><img id=Codehighlighter1_105_172_Open_Image style="DISPLAY: inline" onclick="this.style.display='none'; Codehighlighter1_105_172_Open_Text.style.display='none'; Codehighlighter1_105_172_Closed_Image.style.display='inline'; Codehighlighter1_105_172_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_105_172_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_105_172_Closed_Text.style.display='none'; Codehighlighter1_105_172_Open_Image.style.display='inline'; Codehighlighter1_105_172_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000">&nbsp;</span><span id=Codehighlighter1_105_172_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_105_172_Open_Text style="DISPLAY: inline"><span style="COLOR: #000000">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">使用Msxml的一个版本来创建</span><span style="COLOR: #008000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">xmlHttp&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;ActiveXObject(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Msxml2.XMLHTTP</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img id=Codehighlighter1_184_292_Open_Image style="DISPLAY: inline" onclick="this.style.display='none'; Codehighlighter1_184_292_Open_Text.style.display='none'; Codehighlighter1_184_292_Closed_Image.style.display='inline'; Codehighlighter1_184_292_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_184_292_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_184_292_Closed_Text.style.display='none'; Codehighlighter1_184_292_Open_Image.style.display='inline'; Codehighlighter1_184_292_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>}</span></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000">&nbsp;(e)&nbsp;</span><span id=Codehighlighter1_184_292_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_184_292_Open_Text style="DISPLAY: inline"><span style="COLOR: #000000">{<br><img id=Codehighlighter1_190_258_Open_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_190_258_Open_Text.style.display='none'; Codehighlighter1_190_258_Closed_Image.style.display='inline'; Codehighlighter1_190_258_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_190_258_Closed_Image style="DISPLAY: inline" onclick="this.style.display='none'; Codehighlighter1_190_258_Closed_Text.style.display='none'; Codehighlighter1_190_258_Open_Image.style.display='inline'; Codehighlighter1_190_258_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top></span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000">&nbsp;</span><span id=Codehighlighter1_190_258_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: inline; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_190_258_Open_Text style="DISPLAY: none"><span style="COLOR: #000000">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">使用它的另外一个对象来创建</span><span style="COLOR: #008000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">xmlHttp&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;ActiveXObject(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Microsoft.XMLHTTP</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img id=Codehighlighter1_271_290_Open_Image onclick="this.style.display='none'; Codehighlighter1_271_290_Open_Text.style.display='none'; Codehighlighter1_271_290_Closed_Image.style.display='inline'; Codehighlighter1_271_290_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_271_290_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_271_290_Closed_Text.style.display='none'; Codehighlighter1_271_290_Open_Image.style.display='inline'; Codehighlighter1_271_290_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>}</span></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000">&nbsp;(e2)&nbsp;</span><span id=Codehighlighter1_271_290_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_271_290_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>xmlHttp&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_349_415_Open_Image onclick="this.style.display='none'; Codehighlighter1_349_415_Open_Text.style.display='none'; Codehighlighter1_349_415_Closed_Image.style.display='inline'; Codehighlighter1_349_415_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_349_415_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_349_415_Closed_Text.style.display='none'; Codehighlighter1_349_415_Open_Image.style.display='inline'; Codehighlighter1_349_415_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">xmlHttp&nbsp;</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">typeof</span><span style="COLOR: #000000">&nbsp;XMLHttpRequest&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;'undefined')&nbsp;</span><span id=Codehighlighter1_349_415_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_349_415_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">创建面向其它非微软浏览器的XMLHttpRequest对象</span><span style="COLOR: #008000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">xmlHttp&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;XMLHttpRequest();<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">&lt;/</span><span style="COLOR: #000000">script</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<br>这个过程分为三步，首先我们定义一个xmlHttp来引用创建的XMLHttpRequest。然后，我们尝试在微软的浏览器中创建该对象，先用Msxml.XMLHTTP对象来创建，如果失败再尝试用macrosoft.XMLHTTP来创建它．最后，我们面向非微软浏览器来创建该对象．<br>　这样，我们创建了一个XMLHttpRequest对象，下面我们来看如何发出一个XMLHttpRequest请求。
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;executeXMLHttpRequest(callback,url)<br><img id=Codehighlighter1_45_396_Open_Image onclick="this.style.display='none'; Codehighlighter1_45_396_Open_Text.style.display='none'; Codehighlighter1_45_396_Closed_Image.style.display='inline'; Codehighlighter1_45_396_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_45_396_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_45_396_Closed_Text.style.display='none'; Codehighlighter1_45_396_Open_Image.style.display='inline'; Codehighlighter1_45_396_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_45_396_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_45_396_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">处理非微软浏览器的情况</span><span style="COLOR: #008000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(window.XMLHttpRequest)&nbsp;&nbsp;<br><img id=Codehighlighter1_91_207_Open_Image onclick="this.style.display='none'; Codehighlighter1_91_207_Open_Text.style.display='none'; Codehighlighter1_91_207_Closed_Image.style.display='inline'; Codehighlighter1_91_207_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_91_207_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_91_207_Closed_Text.style.display='none'; Codehighlighter1_91_207_Open_Image.style.display='inline'; Codehighlighter1_91_207_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;</span><span id=Codehighlighter1_91_207_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_91_207_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;xhr</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;XMLHttpRequest();<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;xhr.onreadystatechange&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;callback;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;xhr.open(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Get</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,url,</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);&nbsp;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;xhr.send(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);&nbsp;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">处理微软浏览器的情况</span><span style="COLOR: #008000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(window.ActiveXObject)<br><img id=Codehighlighter1_254_395_Open_Image onclick="this.style.display='none'; Codehighlighter1_254_395_Open_Text.style.display='none'; Codehighlighter1_254_395_Closed_Image.style.display='inline'; Codehighlighter1_254_395_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_254_395_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_254_395_Closed_Text.style.display='none'; Codehighlighter1_254_395_Open_Image.style.display='inline'; Codehighlighter1_254_395_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;</span><span id=Codehighlighter1_254_395_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_254_395_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;xhr</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;ActiveXObject(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">macrosoft.XMLHttp</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(xhr)<br><img id=Codehighlighter1_312_393_Open_Image onclick="this.style.display='none'; Codehighlighter1_312_393_Open_Text.style.display='none'; Codehighlighter1_312_393_Closed_Image.style.display='inline'; Codehighlighter1_312_393_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_312_393_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_312_393_Closed_Text.style.display='none'; Codehighlighter1_312_393_Open_Image.style.display='inline'; Codehighlighter1_312_393_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top></span><span id=Codehighlighter1_312_393_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_312_393_Open_Text><span style="COLOR: #000000">{&nbsp;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;xhr.onreadystatechage</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">callback;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;xhr.open(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Get</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,url,</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;xhr.send();&nbsp;&nbsp;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>}</span></span></div>
</span><br>由上面可见，执行XMLHttpRequest实际上大多数代码还是用在处理浏览器的区别上面，针对不同的浏览器它还是要做出不同的处理，但是这样看上去也非常的直观。<br>&nbsp;在上面的代码中，最关键的是：<br>xhr.onreadystatechage=callback&nbsp;&nbsp; 它定义了回调函数，一旦响应它就会自动执行。<br>xhr.open(""Get",url,true);&nbsp;&nbsp;&nbsp;true表示您想要异步执行该请求。<br><br>对于callback来说，我们有：<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id=Codehighlighter1_31_268_Open_Image onclick="this.style.display='none'; Codehighlighter1_31_268_Open_Text.style.display='none'; Codehighlighter1_31_268_Closed_Image.style.display='inline'; Codehighlighter1_31_268_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_31_268_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_31_268_Closed_Text.style.display='none'; Codehighlighter1_31_268_Open_Image.style.display='inline'; Codehighlighter1_31_268_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align=top><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;processAjaxResponse()&nbsp;</span><span id=Codehighlighter1_31_268_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_31_268_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">状态标识为已完成</span><span style="COLOR: #008000"><br><img id=Codehighlighter1_71_266_Open_Image onclick="this.style.display='none'; Codehighlighter1_71_266_Open_Text.style.display='none'; Codehighlighter1_71_266_Closed_Image.style.display='inline'; Codehighlighter1_71_266_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_71_266_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_71_266_Closed_Text.style.display='none'; Codehighlighter1_71_266_Open_Image.style.display='inline'; Codehighlighter1_71_266_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(xhr.readyState&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">)&nbsp;</span><span id=Codehighlighter1_71_266_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_71_266_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">已就绪</span><span style="COLOR: #008000"><br><img id=Codehighlighter1_106_164_Open_Image onclick="this.style.display='none'; Codehighlighter1_106_164_Open_Text.style.display='none'; Codehighlighter1_106_164_Closed_Image.style.display='inline'; Codehighlighter1_106_164_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_106_164_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_106_164_Closed_Text.style.display='none'; Codehighlighter1_106_164_Open_Image.style.display='inline'; Codehighlighter1_106_164_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(xhr.status&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">200</span><span style="COLOR: #000000">)&nbsp;</span><span id=Codehighlighter1_106_164_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_106_164_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">502</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">502</span><span style="COLOR: #000000">'votes').innerHTML&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;xhr.responseText;<br><img id=Codehighlighter1_171_262_Open_Image onclick="this.style.display='none'; Codehighlighter1_171_262_Open_Text.style.display='none'; Codehighlighter1_171_262_Closed_Image.style.display='inline'; Codehighlighter1_171_262_Closed_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_171_262_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_171_262_Closed_Text.style.display='none'; Codehighlighter1_171_262_Open_Image.style.display='inline'; Codehighlighter1_171_262_Open_Text.style.display='inline';" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span id=Codehighlighter1_171_262_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_171_262_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">There&nbsp;was&nbsp;a&nbsp;problem&nbsp;retrieving&nbsp;the&nbsp;XML&nbsp;data:<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xhr.statusText);<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000">&nbsp;<br><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align=top></span></div>
&nbsp;就是说，一旦服务器处理完XMLHttpRequest并返回给浏览器，用xhr.onreadystatechange指派的回调方法将自动调用。<br><br>上面差不多就是XMLHttpRequest的整个工作流程，它首先检查XMLHttpRequest的整体状态并且保证它已经完成（readyStatus=4），然后根据服务器的设定询问请求状态，如果一切已经就绪（status=200），那么就执行下面需要的操作。<br><br>&nbsp;&nbsp;知道了XMLHttpRequest的工作流程，我们可以看出，XMLHttpRequest是完全用来向服务器发出一个请求的，它的作用也局限于此，但它的作用是整个ajax实现的关键，因为ajax无非是两个过程，发出请求和响应请求。并且它完全是一种客户端的技术。而XMLHttpRequest正是处理了服务器端和客户端通信的问题所以才会如此的重要。<br>&nbsp; 现在，我们对ajax的原理大概可以有一个了解了。我们可以把服务器端看成一个数据接口，它返回的是一个纯文本流，当然，这个文本流可以是XML格式，可以是Html，可以是Javascript代码，也可以只是一个字符串。这时候，XMLHttpRequest向服务器端请求这个页面，服务器端将文本的结果写入页面，这和普通的web开发流程是一样的，不同的是，客户端在异步获取这个结果后，不是直接显示在页面，而是先由javascript来处理，然后再显示在页面。至于现在流行的很多ajax控件，比如magicajax等，可以返回DataSet等其它数据类型，只是将这个过程封装了的结果，本质上他们并没有什么太大的区别。<br>
<img src="http://www.cnblogs.com/ustbwuyi/aggbug/517233.html?type=1" width="1" height="1" alt=""/><p>评论: 2　<a href="http://www.cnblogs.com/ustbwuyi/archive/2006/09/28/517233.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/ustbwuyi/archive/2006/09/28/517233.html#commentform" target="_blank">发表评论</a></p><p><a href="http://job.cnblogs.com/" target="_blank">找优秀程序员，就在博客园</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/59295/" target="_blank">9大IT科技公司总部览</a><span style="color:gray">(2010-03-21 21:00)</span><br/>· <a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><span style="color:gray">(2010-03-21 19:51)</span><br/>· <a href="http://news.cnblogs.com/n/59292/" target="_blank">意大利研发出“移动虚拟校园”技术</a><span style="color:gray">(2010-03-21 19:33)</span><br/>· <a href="http://news.cnblogs.com/n/59291/" target="_blank">如果 Facebook 是一个国家，它将是第三大人口国</a><span style="color:gray">(2010-03-21 17:50)</span><br/>· <a href="http://news.cnblogs.com/n/59290/" target="_blank">德国公司推出Android平板电脑WePad</a><span style="color:gray">(2010-03-21 17:43)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>DOM模型概述</title><link>http://www.cnblogs.com/ustbwuyi/archive/2006/08/24/485095.html</link><dc:creator>ustbwuyi</dc:creator><author>ustbwuyi</author><pubDate>Thu, 24 Aug 2006 03:06:00 GMT</pubDate><guid>http://www.cnblogs.com/ustbwuyi/archive/2006/08/24/485095.html</guid><description><![CDATA[<p>阅读: 1610 评论: 0 作者: <a href="http://www.cnblogs.com/ustbwuyi/" target="_blank">ustbwuyi</a> 发表于 2006-08-24 11:06 <a href="http://www.cnblogs.com/ustbwuyi/archive/2006/08/24/485095.html" target="_blank">原文链接</a></p>&nbsp;&nbsp;<br>&nbsp;&nbsp; 自从W3C建立了DOM标准 (W3C DOM)之后，以及DOM和浏览器兼容之后，DOM在实际应用中越来越广泛。<br>&nbsp;&nbsp; DOM是Document&nbsp;&nbsp;Object Model的简称，中文名称为文档对象模型。它的主要作用是建立网页与 Script 或程序语言沟通的桥梁。<br>
<p>&nbsp;&nbsp; 我们平时可操作及建立文件的属性、方法及事件都以并且用&#8220;对象&#8221;来展现（例如，document 就代表&#8220;文件本身&#8221;这个对象，table 对象则代表 HTML 的表格对象等等）。这些对象可以由当今大多数的浏览器以 Script 来取用。</p>
<p>&nbsp;&nbsp; DOM 常用来和JavaScript交互，也就是说程序以 JavaScript写成，但使用 DOM 来存取页面及其元素。它们两者之间的结合非常紧密，甚至可以说如果没有DOM，我们在使用javascript的时候是不可想象的，因为我们每解析一个节点一个元素都要耗费很多精力，DOM 本身是设计为一种独立的程序语言，以一致的 API 存取文件的结构表述；当然除了JavaScript，DOM可还可以与任何程序语言共同运作，如C/C++、VB、VBS。<br>&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp; 在和JavaScript进行交互的时候，DOM主要用来解析XML文档，当你的应用程序需要不断地导航、修改文档或随机地一次访问整个文档时，我们一般就使用DOM来解析。<br>&nbsp;&nbsp; 在使用DOM进行解析的时候，它在内存中构建起一棵完整的解析树，借此实现对整个XML文档的全面、动态访问。也就是说，它的解析是有层次的，即将所有的html中的元素都解析成树上层次分明的节点，然后我们可以对这些节点进行增删改查等操作，这是对DOM模型的作用的最完善的总结。<br>&nbsp;&nbsp; 和SAX不同，SAX是顺序解析的，与DOM相比，SAX解析器能提供更好的性能优势，它提供对XML文档内容的有效低级访问。<br>&nbsp;&nbsp; SAX模型最大的优点是内存消耗小，因为整个文档无需一次加载到内存中，这使SAX解析器可以解析大于系统内存的文档。另外，你无需像在DOM中那样为所有节点创建对象。最后，SAX&#8220;推&#8221;模型可用于广播环境，能够同时注册多个ContentHandler，并行接收事件，而不是在一个管道中一个接一个地进行处理。但是SAX的一些缺点使它的流行性不如DOM。</p>
<p>&nbsp;&nbsp; DOM的使用非常简单。你可以随机地访问XML文档，由于整个树都构建在内存中，因此可以通过DOM API修改这些节点，例如增加一个子节点或修改、删除一个节点。&nbsp;<br>&nbsp; 不过，虽然内存树结构提供了很好的导航支持，但仍有一些解析策略问题需要仔细考虑。首先，整个XML文档必须一次解析完成，不可能只做部分解析；其次是效率问题，在内存中加载整个文档和构建完整树结构的成本很高，尤其当文档非常大的时候。典型地，DOM树的容量比文档容量要大一个数量级，所以它要消耗大量内存；第三，一般的DOM节点类型在互操作性上有优势，但对于对象类型绑定也许不是最好的。<br></p>
<p><br>&nbsp;</p>
<br>&nbsp; 
<img src="http://www.cnblogs.com/ustbwuyi/aggbug/485095.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/ustbwuyi/archive/2006/08/24/485095.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/ustbwuyi/archive/2006/08/24/485095.html#commentform" target="_blank">发表评论</a></p><p><a href="http://job.cnblogs.com/" target="_blank">找优秀程序员，就在博客园</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/59295/" target="_blank">9大IT科技公司总部览</a><span style="color:gray">(2010-03-21 21:00)</span><br/>· <a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><span style="color:gray">(2010-03-21 19:51)</span><br/>· <a href="http://news.cnblogs.com/n/59292/" target="_blank">意大利研发出“移动虚拟校园”技术</a><span style="color:gray">(2010-03-21 19:33)</span><br/>· <a href="http://news.cnblogs.com/n/59291/" target="_blank">如果 Facebook 是一个国家，它将是第三大人口国</a><span style="color:gray">(2010-03-21 17:50)</span><br/>· <a href="http://news.cnblogs.com/n/59290/" target="_blank">德国公司推出Android平板电脑WePad</a><span style="color:gray">(2010-03-21 17:43)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>C# 常用函数和方法集（转载）</title><link>http://www.cnblogs.com/ustbwuyi/archive/2006/08/15/477240.html</link><dc:creator>ustbwuyi</dc:creator><author>ustbwuyi</author><pubDate>Tue, 15 Aug 2006 03:31:00 GMT</pubDate><guid>http://www.cnblogs.com/ustbwuyi/archive/2006/08/15/477240.html</guid><description><![CDATA[<p>阅读: 277 评论: 0 作者: <a href="http://www.cnblogs.com/ustbwuyi/" target="_blank">ustbwuyi</a> 发表于 2006-08-15 11:31 <a href="http://www.cnblogs.com/ustbwuyi/archive/2006/08/15/477240.html" target="_blank">原文链接</a></p><div class=postTitle><a href="http://blog.csdn.net/gztoby/archive/2004/08/25/84007.aspx"><img height=13 src="http://blog.csdn.net/images/authorship.gif" width=15 border=0>&nbsp;C#.Net 常用函数和方法集</a></div>
<div class=postText>
<table cellSpacing=1 cellPadding=0 width="79%" bgColor=#ffffcc border=0>
    <tbody>
        <tr>
            <td colSpan=3></td>
        </tr>
        <tr>
            <td width="100%" colSpan=3><span id=_ctl0_ContentLabel>1、DateTime&nbsp;&nbsp;&nbsp;数字型&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.DateTime&nbsp;currentTime=<font color=blue>new</font>&nbsp;System.DateTime();&nbsp;&nbsp;<br>&nbsp;&nbsp;1.1&nbsp;取当前年月日时分秒&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentTime=System.DateTime.Now;&nbsp;&nbsp;<br>&nbsp;&nbsp;1.2&nbsp;取当前年&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>int</font>&nbsp;年=currentTime.Year;&nbsp;&nbsp;<br>&nbsp;&nbsp;1.3&nbsp;取当前月&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>int</font>&nbsp;月=currentTime.Month;&nbsp;&nbsp;<br>&nbsp;&nbsp;1.4&nbsp;取当前日&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>int</font>&nbsp;日=currentTime.Day;&nbsp;&nbsp;<br>&nbsp;&nbsp;1.5&nbsp;取当前时&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>int</font>&nbsp;时=currentTime.Hour;&nbsp;&nbsp;<br>&nbsp;&nbsp;1.6&nbsp;取当前分&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>int</font>&nbsp;分=currentTime.Minute;&nbsp;&nbsp;<br>&nbsp;&nbsp;1.7&nbsp;取当前秒&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>int</font>&nbsp;秒=currentTime.Second;&nbsp;&nbsp;<br>&nbsp;&nbsp;1.8&nbsp;取当前毫秒&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>int</font>&nbsp;毫秒=currentTime.Millisecond;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;（变量可用中文）&nbsp;&nbsp;<br><br>2、Int32.Parse(变量)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Int32.Parse("常量")&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;字符型转换&nbsp;转为32位数字型&nbsp;&nbsp;<br><br>3、&nbsp;&nbsp;变量.ToString()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;字符型转换&nbsp;转为字符串&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;12345.ToString("n");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=green>//生成&nbsp;&nbsp;&nbsp;12,345.00&nbsp;&nbsp;<br></font>&nbsp;&nbsp;&nbsp;12345.ToString("C");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=green>//生成&nbsp;￥12,345.00&nbsp;&nbsp;<br></font>&nbsp;&nbsp;&nbsp;12345.ToString("e");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=green>//生成&nbsp;1.234500e+004&nbsp;&nbsp;<br></font>&nbsp;&nbsp;&nbsp;12345.ToString("f4");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=green>//生成&nbsp;12345.0000&nbsp;&nbsp;<br></font>&nbsp;&nbsp;&nbsp;12345.ToString("x");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=green>//生成&nbsp;3039&nbsp;&nbsp;(16进制)&nbsp;&nbsp;<br></font>&nbsp;&nbsp;&nbsp;12345.ToString("p");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=green>//生成&nbsp;1,234,500.00%&nbsp;&nbsp;<br></font><br><br>4、变量.Length&nbsp;&nbsp;数字型&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;取字串长度：&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如：&nbsp;<font color=blue>string</font>&nbsp;str="中国";&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>int</font>&nbsp;Len&nbsp;<font color=red>=</font>&nbsp;str.Length&nbsp;;&nbsp;&nbsp;&nbsp;&nbsp;<font color=green>//Len是自定义变量，&nbsp;str是求测的字串的变量名&nbsp;&nbsp;<br></font><br>5、System.Text.Encoding.Default.GetBytes(变量)&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;字码转换&nbsp;转为比特码&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如：byte[]&nbsp;bytStr&nbsp;<font color=red>=</font>&nbsp;System.Text.Encoding.Default.GetBytes(str);&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;然后可得到比特长度：&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;len&nbsp;<font color=red>=</font>&nbsp;bytStr.Length;&nbsp;&nbsp;<br><br>6、System.Text.StringBuilder("")&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;字符串相加，（+号是不是也一样？）&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;如：System.Text.StringBuilder&nbsp;sb&nbsp;<font color=red>=</font>&nbsp;<font color=blue>new</font>&nbsp;System.Text.StringBuilder("");&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb.Append("中华");&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb.Append("人民");&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb.Append("共和国");&nbsp;&nbsp;<br><br>7、变量.Substring(参数1,参数2);&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;截取字串的一部分，参数1为左起始位数，参数2为截取几位。&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;如：<font color=blue>string</font>&nbsp;s1&nbsp;<font color=red>=</font>&nbsp;str.Substring(0,2);&nbsp;&nbsp;<br><br>8、String&nbsp;user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString();&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;取远程用户IP地址&nbsp;&nbsp;<br><br>9、穿过代理服务器取远程用户真实IP地址：&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;<font color=blue>if</font>(Request.ServerVariables["HTTP_VIA"]!=<font color=blue>null</font>){&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>string</font>&nbsp;&nbsp;user_IP=Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<font color=blue>else</font>{&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>string</font>&nbsp;&nbsp;user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString();&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>10、&nbsp;&nbsp;Session["变量"];&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;存取Session值；&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如，赋值：&nbsp;&nbsp;Session["username"]="小布什";&nbsp;&nbsp;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;取值：&nbsp;&nbsp;Object&nbsp;objName=Session["username"];&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;strName=objName.ToString();&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;清空：&nbsp;&nbsp;Session.RemoveAll();&nbsp;&nbsp;<br><br>11、String&nbsp;str=Request.QueryString["变量"];&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用超链接传送变量。&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如在任一页中建超链接:&lt;a&nbsp;href=Edit.aspx?fbid=23&gt;点击&lt;/a&gt;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在Edit.aspx页中取值：String&nbsp;str=Request.QueryString["fdid"];&nbsp;&nbsp;<br><br>12、DOC对象.CreateElement("新建节点名");&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;创建XML文档新节点&nbsp;&nbsp;<br><br>13、父节点.AppendChild(子节点)；&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;将新建的子节点加到XML文档父节点下&nbsp;&nbsp;<br><br>14、&nbsp;父节点.RemoveChild(节点);&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;删除节点&nbsp;&nbsp;<br><br>15、Response&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write("字串")；&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(变量)；&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;向页面输出。&nbsp;&nbsp;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Redirect("URL地址"）；&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;跳转到URL指定的页面&nbsp;&nbsp;<br><br>16、<font color=blue>char</font>.IsWhiteSpce(字串变量，位数)——逻辑型&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;查指定位置是否空字符；&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;如：&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>string</font>&nbsp;str="中国&nbsp;&nbsp;人民";&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(<font color=blue>char</font>.IsWhiteSpace(str,2));&nbsp;<font color=green>//结果为：True,&nbsp;第一个字符是0位，2是第三个字符。&nbsp;&nbsp;<br></font><br>17、<font color=blue>char</font>.IsPunctuation('字符')&nbsp;&nbsp;--逻辑型&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;查字符是否是标点符号&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;如：Response.Write(<font color=blue>char</font>.IsPunctuation('A'));&nbsp;&nbsp;&nbsp;<font color=green>//返回：False&nbsp;&nbsp;<br></font><br>18、(<font color=blue>int</font>)'字符'&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;把字符转为数字，查代码点，注意是单引号。&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;如：&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write((<font color=blue>int</font>)'中');&nbsp;&nbsp;&nbsp;<font color=green>//结果为中字的代码：20013&nbsp;&nbsp;<br></font><br>19、(<font color=blue>char</font>)代码&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;把数字转为字符，查代码代表的字符。&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;如：&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;Response.Write((<font color=blue>char</font>)22269);&nbsp;&nbsp;&nbsp;<font color=green>//返回&#8220;国&#8221;字。&nbsp;&nbsp;<br></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>20、&nbsp;Trim()&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;清除字串前后空格&nbsp;&nbsp;<br><br>21&nbsp;、字串变量.Replace("子字串","替换为")&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;字串替换&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如：&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>string</font>&nbsp;str="中国";&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str=str.Replace("国","央");&nbsp;&nbsp;<font color=green>//将国字换为央字&nbsp;&nbsp;<br></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(str);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=green>//输出结果为&#8220;中央&#8221;&nbsp;&nbsp;<br></font><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;再如：（这个非常实用）&nbsp;&nbsp;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>string</font>&nbsp;str="这是&lt;script&gt;脚本";&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str=str.Replace("&lt;","&lt;font&gt;&lt;&lt;/font&gt;");&nbsp;&nbsp;<font color=green>//将左尖括号替换为&lt;font&gt;&nbsp;与&nbsp;&lt;&nbsp;与&nbsp;&lt;/font&gt;&nbsp;（或换为&amp;lt，但估计经XML存诸后，再提出仍会还原）&nbsp;&nbsp;<br></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(str);&nbsp;<font color=green>//显示为：&#8220;这是&lt;script&gt;脚本&#8221;&nbsp;&nbsp;<br></font><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果不替换，&lt;script&gt;将不显示，如果是一段脚本，将运行；而替换后，脚本将不运行。&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;这段代码的价值在于：你可以让一个文本中的所有HTML标签失效，全部显示出来，保护你的具有交互<a id=SiteKey href="http://xfok.com/Search.Aspx?Keyword=%D0%D4&amp;Action=Search&amp;imageField.x=16&amp;imageField.y=11" target=_blank><u><font color=#0000ff>性</font></u></a>的站点。&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;具体实现：将你的表单提交按钮脚本加上下面代码：&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=blue>string</font>&nbsp;strSubmit=label1.Text;&nbsp;&nbsp;&nbsp;<font color=green>//label1是你让用户提交数据的控件ID。&nbsp;&nbsp;<br></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strSubmit=strSubmit.Replace("&lt;","&lt;font&gt;&lt;&lt;/font&gt;");&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;然后保存或输出strSubmit。&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用此方法还可以简单实现UBB代码。&nbsp;&nbsp;<br><br>22、Math.Max(i,j)&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;取i与j中的最大值&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;如&nbsp;<font color=blue>int</font>&nbsp;x=Math.Max(5,10);&nbsp;&nbsp;<font color=green>//&nbsp;x将取值&nbsp;10</font></span> <br>
            <p>
            <table align=right>
                <tbody>
                    <tr>
                        <td></td>
                    </tr>
                </tbody>
            </table>
            转载至: <a href="http://blog.csdn.net/ericfine">http://blog.csdn.net/ericfine</a>
            <style type=text/css>
            <!--
            BODY { FONT-FAMILY: Verdana,Arial,宋体; FONT-SIZE: 12px}
            td{FONT-FAMILY: Verdana,Arial,宋体; FONT-SIZE: 12px;color:#000000;}
            A:link {text-decoration: none; color:#000000}
            A:visited  {text-decoration: none; color:#000000}}
            A:active {text-decoration: none; color: #c50000}
            A:hover {text-decoration: underline; color: #c50000}
            .a {color:#ffffff;}
            .a1 {font-size:14px;color:#2C7494;}
            .link_topic {text-decoration: none; font-size:18px}
            .formitem {BACKGROUND-COLOR: #ffffff; BORDER: #000000 1px solid; FONT-SIZE: 12pt}
            //-->
            </style>
            <br><asp:label <br><asp:label <br><asp:label <br><asp:label <br><asp:textbox <br></p>
            </asp:textbox></asp:label></asp:label></asp:label></asp:label></td>
        </tr>
    </tbody>
</table>
</div>
<img src="http://www.cnblogs.com/ustbwuyi/aggbug/477240.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/ustbwuyi/archive/2006/08/15/477240.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/ustbwuyi/archive/2006/08/15/477240.html#commentform" target="_blank">发表评论</a></p><p><a href="http://job.cnblogs.com/" target="_blank">找优秀程序员，就在博客园</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/59295/" target="_blank">9大IT科技公司总部览</a><span style="color:gray">(2010-03-21 21:00)</span><br/>· <a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><span style="color:gray">(2010-03-21 19:51)</span><br/>· <a href="http://news.cnblogs.com/n/59292/" target="_blank">意大利研发出“移动虚拟校园”技术</a><span style="color:gray">(2010-03-21 19:33)</span><br/>· <a href="http://news.cnblogs.com/n/59291/" target="_blank">如果 Facebook 是一个国家，它将是第三大人口国</a><span style="color:gray">(2010-03-21 17:50)</span><br/>· <a href="http://news.cnblogs.com/n/59290/" target="_blank">德国公司推出Android平板电脑WePad</a><span style="color:gray">(2010-03-21 17:43)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/59293/" target="_blank">五个广泛流传的对大龄程序员的误解</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item></channel></rss>