﻿<?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>BlogJava-我爱我的家园!-文章分类-C#学习</title><link>http://www.blogjava.net/Yipak/category/34179.html</link><description>成功在于你是否努力,希望在于你是否相信自己! </description><language>zh-cn</language><lastBuildDate>Fri, 05 Sep 2008 17:06:35 GMT</lastBuildDate><pubDate>Fri, 05 Sep 2008 17:06:35 GMT</pubDate><ttl>60</ttl><item><title>C#深入详解[4.1  数据类型]</title><link>http://www.blogjava.net/Yipak/articles/227335.html</link><dc:creator>死神</dc:creator><author>死神</author><pubDate>Fri, 05 Sep 2008 14:26:00 GMT</pubDate><guid>http://www.blogjava.net/Yipak/articles/227335.html</guid><wfw:comment>http://www.blogjava.net/Yipak/comments/227335.html</wfw:comment><comments>http://www.blogjava.net/Yipak/articles/227335.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Yipak/comments/commentRss/227335.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Yipak/services/trackbacks/227335.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 4.1  数据类型		4.1.1  C#的数据类型		C#是强类型语言，因此每个变量和对象都必须具有声明类型。C#开发语言的数据类型包括值类型和引用类型。		4.1.2  C#值类型		C#开发语言的值类型有15种，包括bool、byte、char、decimal、double、enum、float、int、long、sbyte、short、struct、uint、ulong和us...&nbsp;&nbsp;<a href='http://www.blogjava.net/Yipak/articles/227335.html'>阅读全文</a><img src ="http://www.blogjava.net/Yipak/aggbug/227335.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Yipak/" target="_blank">死神</a> 2008-09-05 22:26 <a href="http://www.blogjava.net/Yipak/articles/227335.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c# 文件操作</title><link>http://www.blogjava.net/Yipak/articles/226932.html</link><dc:creator>死神</dc:creator><author>死神</author><pubDate>Thu, 04 Sep 2008 06:24:00 GMT</pubDate><guid>http://www.blogjava.net/Yipak/articles/226932.html</guid><wfw:comment>http://www.blogjava.net/Yipak/comments/226932.html</wfw:comment><comments>http://www.blogjava.net/Yipak/articles/226932.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Yipak/comments/commentRss/226932.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Yipak/services/trackbacks/226932.html</trackback:ping><description><![CDATA[
		<p>C#追加文件<br />StreamWriter sw = File.AppendText(Server.MapPath(”.”)+”<a href="file://myText.txt/"><font color="#46a8c8">\\myText.txt</font></a>“);<br />sw.WriteLine(”追逐理想”);<br />sw.WriteLine(”kzlll”);<br />sw.WriteLine(”.NET笔记”);<br />sw.Flush();<br />sw.Close();</p>
		<p>C#拷贝文件<br />string OrignFile,NewFile;<br />OrignFile = Server.MapPath(”.”)+”<a href="file://myText.txt/"><font color="#46a8c8">\\myText.txt</font></a>“;<br />NewFile = Server.MapPath(”.”)+”<a href="file://myTextCopy.txt/"><font color="#46a8c8">\\myTextCopy.txt</font></a>“;<br />File.Copy(OrignFile,NewFile,true);</p>
		<p>C#删除文件<br />string delFile = Server.MapPath(”.”)+”<a href="file://myTextCopy.txt/"><font color="#46a8c8">\\myTextCopy.txt</font></a>“;<br />File.Delete(delFile);</p>
		<p>C#移动文件<br />string OrignFile,NewFile;<br />OrignFile = Server.MapPath(”.”)+”<a href="file://myText.txt/"><font color="#46a8c8">\\myText.txt</font></a>“;<br />NewFile = Server.MapPath(”.”)+”<a href="file://myTextCopy.txt/"><font color="#46a8c8">\\myTextCopy.txt</font></a>“;<br />File.Move(OrignFile,NewFile);</p>
		<p>C#创建目录<br />// 创建目录c:\sixAge<br />DirectoryInfo d=Directory.CreateDirectory(”c:\\sixAge”);<br />// d1指向c:\sixAge\sixAge1<br />DirectoryInfo d1=d.CreateSubdirectory(”sixAge1″);<br />// d2指向c:\sixAge\sixAge1\sixAge1_1<br />DirectoryInfo d2=d1.CreateSubdirectory(”sixAge1_1″);<br />// 将当前目录设为c:\sixAge<br />Directory.SetCurrentDirectory(”c:\\sixAge”);<br />// 创建目录c:\sixAge\sixAge2<br />Directory.CreateDirectory(”sixAge2″);<br />// 创建目录c:\sixAge\sixAge2\sixAge2_1<br />Directory.CreateDirectory(”sixAge2\\sixAge2_1″);</p>
		<p>递归删除文件夹及文件<br />&lt;%@ Page Language=C#%&gt;<br />&lt;%@ Import namespace=”System.IO”%&gt;<br />&lt;Script runat=server&gt;<br />public void DeleteFolder(string dir)<br />{<br />    if (Directory.Exists(dir)) //如果存在这个文件夹删除之<br />    {<br />        foreach(string d in Directory.GetFileSystemEntries(dir))<br />        {<br />            if(File.Exists(d))<br />                File.Delete(d); //直接删除其中的文件<br />            else<br />                DeleteFolder(d); //递归删除子文件夹<br />        }<br />        Directory.Delete(dir); //删除已空文件夹<br />        Response.Write(dir+” 文件夹删除成功”);<br />    }<br />    else<br />        Response.Write(dir+” 该文件夹不存在”); //如果文件夹不存在则提示<br />}</p>
		<p>protected void Page_Load (Object sender ,EventArgs e)<br />{<br />    string Dir=”D:\\gbook\\11″;<br />    DeleteFolder(Dir); //调用函数删除文件夹<br />}</p>
		<p>
				<br />// ======================================================<br />  // 实现一个静态方法将指定文件夹下面的所有内容copy到目标文件夹下面<br />  // 如果目标文件夹为只读属性就会报错。<br />  // April 18April2005 In STU<br />  // ======================================================<br />  public static void CopyDir(string srcPath,string aimPath)<br />  {<br />   try<br />   {<br />    // 检查目标目录是否以目录分割字符结束如果不是则添加之<br />    if(aimPath[aimPath.Length-1] != Path.DirectorySeparatorChar)<br />     aimPath += Path.DirectorySeparatorChar;<br />    // 判断目标目录是否存在如果不存在则新建之<br />    if(!Directory.Exists(aimPath)) Directory.CreateDirectory(aimPath);<br />    // 得到源目录的文件列表，该里面是包含文件以及目录路径的一个数组<br />    // 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法<br />    // string[] fileList = Directory.GetFiles(srcPath);<br />    string[] fileList = Directory.GetFileSystemEntries(srcPath);<br />    // 遍历所有的文件和目录<br />    foreach(string file in fileList)<br />    {<br />     // 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件<br />     if(Directory.Exists(file))<br />      CopyDir(file,aimPath+Path.GetFileName(file));<br />      // 否则直接Copy文件<br />     else<br />      File.Copy(file,aimPath+Path.GetFileName(file),true);<br />    }<br />   }<br />   catch (Exception e)<br />   {<br />    MessageBox.Show (e.ToString());<br />   }<br />  }</p>
		<p>  // ======================================================<br />  // 实现一个静态方法将指定文件夹下面的所有内容Detele<br />  // 测试的时候要小心操作，删除之后无法恢复。<br />  // April 18April2005 In STU<br />  // ======================================================<br />  public static void DeleteDir(string aimPath)<br />  {<br />   try<br />   {<br />    // 检查目标目录是否以目录分割字符结束如果不是则添加之<br />    if(aimPath[aimPath.Length-1] != Path.DirectorySeparatorChar)<br />     aimPath += Path.DirectorySeparatorChar;<br />    // 得到源目录的文件列表，该里面是包含文件以及目录路径的一个数组<br />    // 如果你指向Delete目标文件下面的文件而不包含目录请使用下面的方法<br />    // string[] fileList = Directory.GetFiles(aimPath);<br />    string[] fileList = Directory.GetFileSystemEntries(aimPath);<br />    // 遍历所有的文件和目录<br />    foreach(string file in fileList)<br />    {<br />     // 先当作目录处理如果存在这个目录就递归Delete该目录下面的文件<br />     if(Directory.Exists(file))<br />     {<br />      DeleteDir(aimPath+Path.GetFileName(file));<br />     }<br />      // 否则直接Delete文件<br />     else<br />     {<br />      File.Delete (aimPath+Path.GetFileName(file));<br />     }<br />    }<br />    //删除文件夹<br />    System.IO .Directory .Delete (aimPath,true);<br />   }<br />   catch (Exception e)<br />   {<br />    MessageBox.Show (e.ToString());<br />   }<br />  }<br /> </p>
		<p> </p>
		<p>需要引用命名空间：<br />using System.IO;</p>
		<p>/**//// &lt;summary&gt;<br />  /// 拷贝文件夹(包括子文件夹)到指定文件夹下,源文件夹和目标文件夹均需绝对路径. 格式: CopyFolder(源文件夹,目标文件夹);<br />  /// &lt;/summary&gt;<br />  /// &lt;param name=”strFromPath”&gt;&lt;/param&gt;<br />  /// &lt;param name=”strToPath”&gt;&lt;/param&gt;</p>
		<p>  //————————————————–<br />  //作者:明天去要饭  QQ:305725744<br /> //—————————————————</p>
		<p>  public static void CopyFolder(string strFromPath,string strToPath)<br />  {<br />   //如果源文件夹不存在，则创建<br />   if (!Directory.Exists(strFromPath))<br />   {   <br />    Directory.CreateDirectory(strFromPath);<br />   }  </p>
		<p>   //取得要拷贝的文件夹名<br />   string strFolderName = strFromPath.Substring(strFromPath.LastIndexOf(”\\”) + 1,strFromPath.Length - strFromPath.LastIndexOf(”\\”) - 1);  </p>
		<p>   //如果目标文件夹中没有源文件夹则在目标文件夹中创建源文件夹<br />   if (!Directory.Exists(strToPath + “\\” + strFolderName))<br />   {   <br />    Directory.CreateDirectory(strToPath + “\\” + strFolderName);<br />   }<br />   //创建数组保存源文件夹下的文件名<br />   string[] strFiles = Directory.GetFiles(strFromPath);</p>
		<p>   //循环拷贝文件<br />   for(int i = 0;i &lt; strFiles.Length;i++)<br />   {<br />    //取得拷贝的文件名，只取文件名，地址截掉。<br />    string strFileName = strFiles[i].Substring(strFiles[i].LastIndexOf(”\\”) + 1,strFiles[i].Length - strFiles[i].LastIndexOf(”\\”) - 1);<br />    //开始拷贝文件,true表示覆盖同名文件<br />    File.Copy(strFiles[i],strToPath + “\\” + strFolderName + “\\” + strFileName,true);<br />   }<br /> <br />   //创建DirectoryInfo实例<br />   DirectoryInfo dirInfo = new DirectoryInfo(strFromPath);<br />   //取得源文件夹下的所有子文件夹名称<br />   DirectoryInfo[] ZiPath = dirInfo.GetDirectories();<br />   for (int j = 0;j &lt; ZiPath.Length;j++)<br />   {<br />    //获取所有子文件夹名<br />    string strZiPath = strFromPath + “\\” + ZiPath[j].ToString();  <br />    //把得到的子文件夹当成新的源文件夹，从头开始新一轮的拷贝<br />    CopyFolder(strZiPath,strToPath + “\\” + strFolderName);<br />   }<br />  }</p>
<img src ="http://www.blogjava.net/Yipak/aggbug/226932.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Yipak/" target="_blank">死神</a> 2008-09-04 14:24 <a href="http://www.blogjava.net/Yipak/articles/226932.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AJAX for asp.net 插件安装及测试</title><link>http://www.blogjava.net/Yipak/articles/Ajax.html</link><dc:creator>死神</dc:creator><author>死神</author><pubDate>Thu, 04 Sep 2008 06:23:00 GMT</pubDate><guid>http://www.blogjava.net/Yipak/articles/Ajax.html</guid><wfw:comment>http://www.blogjava.net/Yipak/comments/226929.html</wfw:comment><comments>http://www.blogjava.net/Yipak/articles/Ajax.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Yipak/comments/commentRss/226929.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Yipak/services/trackbacks/226929.html</trackback:ping><description><![CDATA[
		<p>AJAX是Asnychronize Javascript and XML（异步Javascript和XML）。其基本原理是当用户触发了网页中的事件时，网页中Javascript代码（理论上VBScript也能完成等效操作）先截获事件，然后在后台利用XmlHttp对象对网页进行提交。在返回的结果中提取需要部分来更新网页。这样免去了加载并没有变化的控件的时间，减少用户等待时间。而且利用AJAX还能轻松完成传统技术不能或者很难完成的特效，比如说拖拉操作。<br /><br />虽然AJAX只是把现有技术进行重新组合，但是与传统编程有很大的区别。初学者学起来可能会感觉不习惯，尤其是目前还没有好的教材。好在微软ASP社区发布了能整合在Visual Studio 2005里的AJAX Extender和AJAX Control Toolkit。前者提供了AJAX技术的核心功能，也就是异步提交；而后者是控件集，内含32个AJAX控件。我先向大家介绍如何安装AJAX Extensionr和AJAX Control Toolkit。<br /><br />首先需要安装.NET Framework 2.0和Visual Studio 2005。<br /><br />微软ASP社区AJAX下载中心：<a href="http://ajax.asp.net/downloads/default.aspx?tabid=47" target="_blank">http://ajax.asp.net/downloads/default.aspx?tabid=47</a><br /><br />1为Ajax Extender的下载链接，只可惜需要Windows正版验证。<br /><br />2为AJAX Control Toolkit的下载链接，点击后会指向另外一个网页，网页中部有两个下载链接一个是2.2MB的完整版，一个是1.5MB的无源代码版。建议下载完全版。<br /><br />3为Ajax Control Toolkit的演示页面。<br />Ajax Extension是MSI安装程序，按照提示即可。安装完成以后会在VS里的控件工具栏里发现"Ajax Extensions"的组。里面有五个控件，具体功能以后介绍。现在就可以编译AJAX程序了。但是要进行编程，还需要下面的步骤。<br /><br />Ajax Control Toolkit只能手动安装。首先将文件解压，由于其中包括实例程序，所以建议解压到方便浏览的位置。然后双击子目录AjaxControlExtender里的AjaxControlExtender.vsi。<br /><br />如果安装了VS就能运行，按照提示即可。其中会提示文件可能会含有有害的代码，不用理会。接着打开VS，在控件工具栏里新建一个组，命名为"Ajax Control Toolkit"<br /><br />在新组里点击右键，选"选择项目"，在弹出对话框里点“浏览”，选择解压出来的文件当中SampleWebsite\Bin子目录中的AjaxControlToolkit.dll文件然后确定退出，如图6。这样一来新组里就多了32个新控件了。<br /></p>
<img src ="http://www.blogjava.net/Yipak/aggbug/226929.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Yipak/" target="_blank">死神</a> 2008-09-04 14:23 <a href="http://www.blogjava.net/Yipak/articles/Ajax.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C#窗口程序启动，能不出现命令行窗口</title><link>http://www.blogjava.net/Yipak/articles/226930.html</link><dc:creator>死神</dc:creator><author>死神</author><pubDate>Thu, 04 Sep 2008 06:23:00 GMT</pubDate><guid>http://www.blogjava.net/Yipak/articles/226930.html</guid><wfw:comment>http://www.blogjava.net/Yipak/comments/226930.html</wfw:comment><comments>http://www.blogjava.net/Yipak/articles/226930.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Yipak/comments/commentRss/226930.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Yipak/services/trackbacks/226930.html</trackback:ping><description><![CDATA[
		<p>如果说在VS里面编译,修改一下配置  <br />   <br />  项目   -&gt;   项目属性   -&gt;   常规   -&gt;   输出类型   =   Windows   应用程序  <br />   <br />  如果说在控制台  <br />   <br />  C:\&gt;csc.exe   /t:winexe   /r:System.Windows.Forms.dll   yourClassName.cs</p>
<img src ="http://www.blogjava.net/Yipak/aggbug/226930.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Yipak/" target="_blank">死神</a> 2008-09-04 14:23 <a href="http://www.blogjava.net/Yipak/articles/226930.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C#动态调用C++编写的DLL函数</title><link>http://www.blogjava.net/Yipak/articles/226313.html</link><dc:creator>死神</dc:creator><author>死神</author><pubDate>Tue, 02 Sep 2008 03:56:00 GMT</pubDate><guid>http://www.blogjava.net/Yipak/articles/226313.html</guid><wfw:comment>http://www.blogjava.net/Yipak/comments/226313.html</wfw:comment><comments>http://www.blogjava.net/Yipak/articles/226313.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Yipak/comments/commentRss/226313.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Yipak/services/trackbacks/226313.html</trackback:ping><description><![CDATA[
		<div>
				<span style="FONT-FAMILY: 宋体">动态加载</span>
				<span style="FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="FONT-FAMILY: 宋体">需要使用</span>
				<span style="FONT-FAMILY: 'Courier New'">Windows API</span>
				<span style="FONT-FAMILY: 宋体">函数：</span>
				<span style="FONT-FAMILY: 'Courier New'">LoadLibrary</span>
				<span style="FONT-FAMILY: 宋体">、</span>
				<span style="FONT-FAMILY: 'Courier New'">GetProcAddress</span>
				<span style="FONT-FAMILY: 宋体">以及</span>
				<span style="FONT-FAMILY: 'Courier New'">FreeLibrary</span>
				<span style="FONT-FAMILY: 宋体">。我们可以使用</span>
				<span style="FONT-FAMILY: 'Courier New'">DllImport</span>
				<span style="FONT-FAMILY: 宋体">在</span>
				<span style="FONT-FAMILY: 'Courier New'">C#</span>
				<span style="FONT-FAMILY: 宋体">中使用这三个函数。</span>
		</div>
		<div> </div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">[<span style="COLOR: #2b91af">DllImport</span>(<span style="COLOR: #a31515">"Kernel32"</span>)]</span>
		</div>
		<div align="left">
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">public</span>
				<span style="FONT-FAMILY: 'Courier New'">
						<span style="COLOR: blue">static</span>
						<span style="COLOR: blue">extern</span>
						<span style="COLOR: blue">int</span>
						<span style="COLOR: #030003">GetProcAddress</span>(<span style="COLOR: blue">int</span><span style="COLOR: #030003">handle</span>, <span style="COLOR: #2b91af">String</span><span style="COLOR: #030003">funcname</span>);</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">[<span style="COLOR: #2b91af">DllImport</span>(<span style="COLOR: #a31515">"Kernel32"</span>)]</span>
		</div>
		<div align="left">
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">public</span>
				<span style="FONT-FAMILY: 'Courier New'">
						<span style="COLOR: blue">static</span>
						<span style="COLOR: blue">extern</span>
						<span style="COLOR: blue">int</span>
						<span style="COLOR: #030003">LoadLibrary</span>(<span style="COLOR: #2b91af">String</span><span style="COLOR: #030003">funcname</span>);</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">[<span style="COLOR: #2b91af">DllImport</span>(<span style="COLOR: #a31515">"Kernel32"</span>)]</span>
		</div>
		<div>
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">public</span>
				<span style="FONT-FAMILY: 'Courier New'">
						<span style="COLOR: blue">static</span>
						<span style="COLOR: blue">extern</span>
						<span style="COLOR: blue">int</span>
						<span style="COLOR: #030003">FreeLibrary</span>(<span style="COLOR: blue">int</span><span style="COLOR: #030003">handle</span>);</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 宋体">当我们在</span>
				<span style="FONT-FAMILY: 'Courier New'">C++</span>
				<span style="FONT-FAMILY: 宋体">中动态调用</span>
				<span style="FONT-FAMILY: 'Courier New'">Dll</span>
				<span style="FONT-FAMILY: 宋体">中的函数时，我们一般的方法是：</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 宋体">假设</span>
				<span style="FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="FONT-FAMILY: 宋体">中有一个导出函数，函数原型如下：</span>
		</div>
		<div>
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">BOOL</span>
				<span style="FONT-FAMILY: 'Courier New'">
						<span style="COLOR: blue">__stdcall</span> foo(<span style="COLOR: blue">Object</span> &amp;object, <span style="COLOR: blue">LPVOID</span> lpReserved);</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">1</span>
				<span style="FONT-FAMILY: 宋体">、首先定义相应的函数指针：</span>
		</div>
		<div>
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">typedef</span>
				<span style="FONT-FAMILY: 'Courier New'">
						<span style="COLOR: blue">BOOL</span> (<span style="COLOR: blue">__stdcall</span> *PFOO)(<span style="COLOR: blue">Object</span> &amp;object, <span style="COLOR: blue">LPVOID</span> lpReserved);</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">2</span>
				<span style="FONT-FAMILY: 宋体">、调用</span>
				<span style="FONT-FAMILY: 'Courier New'">LoadLibrary</span>
				<span style="FONT-FAMILY: 宋体">加载</span>
				<span style="FONT-FAMILY: 'Courier New'">dll</span>
				<span style="FONT-FAMILY: 宋体">：</span>
		</div>
		<div>
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">HINSTANCE</span>
				<span style="FONT-FAMILY: 'Courier New'"> hInst = ::LoadLibraryW(dllFileName);</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">3</span>
				<span style="FONT-FAMILY: 宋体">、调用</span>
				<span style="FONT-FAMILY: 'Courier New'">GetProcAddress</span>
				<span style="FONT-FAMILY: 宋体">函数获取要调用函数的地址：</span>
		</div>
		<div>
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">PFOO</span>
				<span style="FONT-FAMILY: 'Courier New'"> foo = (<span style="COLOR: blue">PFOO</span>)GetProcAddress(hInst,"foo");</span>
		</div>
		<div>
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">if</span>
				<span style="FONT-FAMILY: 'Courier New'">(foo == NULL)</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">{</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">    FreeLibrary(hInst);</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">return</span> false;</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">}</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">4</span>
				<span style="FONT-FAMILY: 宋体">、调用</span>
				<span style="FONT-FAMILY: 'Courier New'">foo</span>
				<span style="FONT-FAMILY: 宋体">函数：</span>
		</div>
		<div>
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">BOOL</span>
				<span style="FONT-FAMILY: 'Courier New'"> bRet = foo(object,(<span style="COLOR: blue">LPVOID</span>)NULL);</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">5</span>
				<span style="FONT-FAMILY: 宋体">、使用完后应释放</span>
				<span style="FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="FONT-FAMILY: 宋体">：</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">FreeLibrary(hInst);</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 宋体">那么在</span>
				<span style="FONT-FAMILY: 'Courier New'">C#</span>
				<span style="FONT-FAMILY: 宋体">中应该怎么做呢？方法基本上一样，我们使用委托来代替</span>
				<span style="FONT-FAMILY: 'Courier New'">C++</span>
				<span style="FONT-FAMILY: 宋体">的函数指针，通过</span>
				<span style="FONT-FAMILY: 'Courier New'">.NET Framework 2.0</span>
				<span style="FONT-FAMILY: 宋体">新增的函数</span>
				<span style="FONT-FAMILY: 'Courier New'">GetDelegateForFunctionPointer</span>
				<span style="FONT-FAMILY: 宋体">来得到一个委托的实例：</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 宋体">下面封装了一个类，通过该类我们就可以在</span>
				<span style="FONT-FAMILY: 'Courier New'">C#</span>
				<span style="FONT-FAMILY: 宋体">中动态调用</span>
				<span style="FONT-FAMILY: 'Courier New'">Dll</span>
				<span style="FONT-FAMILY: 宋体">中的函数了：</span>
		</div>
		<div> </div>
		<div align="left">
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">public class</span>
				<span style="FONT-FAMILY: 'Courier New'">
						<span style="COLOR: #2b91af">DLLWrapper</span>
				</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">{</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: green"> API LoadLibrary</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;/summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    [<span style="COLOR: #2b91af">DllImport</span>(<span style="COLOR: #a31515">"Kernel32"</span>)]</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">extern</span><span style="COLOR: blue">int</span><span style="COLOR: #030003">LoadLibrary</span>(<span style="COLOR: #2b91af">String</span><span style="COLOR: #030003">funcname</span>);</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: green"> API GetProcAddress</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;/summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    [<span style="COLOR: #2b91af">DllImport</span>(<span style="COLOR: #a31515">"Kernel32"</span>)]</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">extern</span><span style="COLOR: blue">int</span><span style="COLOR: #030003">GetProcAddress</span>(<span style="COLOR: blue">int</span><span style="COLOR: #030003">handle</span>, <span style="COLOR: #2b91af">String</span><span style="COLOR: #030003">funcname</span>);</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: green"> API FreeLibrary</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;/summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    [<span style="COLOR: #2b91af">DllImport</span>(<span style="COLOR: #a31515">"Kernel32"</span>)]</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">extern</span><span style="COLOR: blue">int</span><span style="COLOR: #030003">FreeLibrary</span>(<span style="COLOR: blue">int</span><span style="COLOR: #030003">handle</span>);</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span></span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">通过非托管函数名转换为对应的委托</span>
				<span style="COLOR: green; FONT-FAMILY: 'Courier New'">, by jingzhongrong</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;/summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;param name="dllModule"&gt;</span></span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">通过</span>
				<span style="COLOR: green; FONT-FAMILY: 'Courier New'">LoadLibrary</span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">获得的</span>
				<span style="COLOR: green; FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">句柄</span>
				<span style="COLOR: gray; FONT-FAMILY: 'Courier New'">&lt;/param&gt;</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;param name="functionName"&gt;</span></span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">非托管函数名</span>
				<span style="COLOR: gray; FONT-FAMILY: 'Courier New'">&lt;/param&gt;</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;param name="t"&gt;</span></span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">对应的委托类型</span>
				<span style="COLOR: gray; FONT-FAMILY: 'Courier New'">&lt;/param&gt;</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;returns&gt;</span></span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">委托实例，可强制转换为适当的委托类型</span>
				<span style="COLOR: gray; FONT-FAMILY: 'Courier New'">&lt;/returns&gt;</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: #2b91af">Delegate</span><span style="COLOR: #030003">GetFunctionAddress</span>(<span style="COLOR: blue">int</span><span style="COLOR: #030003">dllModule</span>, <span style="COLOR: blue">string</span><span style="COLOR: #030003">functionName</span>, <span style="COLOR: #2b91af">Type</span><span style="COLOR: #030003">t</span>)</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    {</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">int</span><span style="COLOR: #030003">address</span> = <span style="COLOR: #030003">GetProcAddress</span>(<span style="COLOR: #030003">dllModule</span>, <span style="COLOR: #030003">functionName</span>);</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">if</span> (<span style="COLOR: #030003">address</span> == 0)</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">           <span style="COLOR: blue">return</span><span style="COLOR: blue">null</span>;</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">else</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">           <span style="COLOR: blue">return</span><span style="COLOR: #2b91af">Marshal</span>.<span style="COLOR: #030003">GetDelegateForFunctionPointer</span>(<span style="COLOR: blue">new</span><span style="COLOR: #2b91af">IntPtr</span>(<span style="COLOR: #030003">address</span>), <span style="COLOR: #030003">t</span>);</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    }</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span></span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">将表示函数地址的</span>
				<span style="COLOR: green; FONT-FAMILY: 'Courier New'">IntPtr</span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">实例转换成对应的委托</span>
				<span style="COLOR: green; FONT-FAMILY: 'Courier New'">, by jingzhongrong</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;/summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: #2b91af">Delegate</span><span style="COLOR: #030003">GetDelegateFromIntPtr</span>(<span style="COLOR: #2b91af">IntPtr</span><span style="COLOR: #030003">address</span>, <span style="COLOR: #2b91af">Type</span><span style="COLOR: #030003">t</span>)</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    {</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">if</span> (<span style="COLOR: #030003">address</span> == <span style="COLOR: #2b91af">IntPtr</span>.<span style="COLOR: #030003">Zero</span>)</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">           <span style="COLOR: blue">return</span><span style="COLOR: blue">null</span>;</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">else</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">           <span style="COLOR: blue">return</span><span style="COLOR: #2b91af">Marshal</span>.<span style="COLOR: #030003">GetDelegateForFunctionPointer</span>(<span style="COLOR: #030003">address</span>, <span style="COLOR: #030003">t</span>);</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    }</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span></span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">将表示函数地址的</span>
				<span style="COLOR: green; FONT-FAMILY: 'Courier New'">int</span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">转换成对应的委托，by jingzhongrong</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: gray">///</span><span style="COLOR: gray">&lt;/summary&gt;</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: #2b91af">Delegate</span><span style="COLOR: #030003">GetDelegateFromIntPtr</span>(<span style="COLOR: blue">int</span><span style="COLOR: #030003">address</span>, <span style="COLOR: #2b91af">Type</span><span style="COLOR: #030003">t</span>)</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    {</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">if</span> (<span style="COLOR: #030003">address</span> == 0)</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">           <span style="COLOR: blue">return</span><span style="COLOR: blue">null</span>;</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">else</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">           <span style="COLOR: blue">return</span><span style="COLOR: #2b91af">Marshal</span>.<span style="COLOR: #030003">GetDelegateForFunctionPointer</span>(<span style="COLOR: blue">new</span><span style="COLOR: #2b91af">IntPtr</span>(<span style="COLOR: #030003">address</span>), <span style="COLOR: #030003">t</span>);</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    }</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">}</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 宋体">通过这个类，我们这样调用</span>
				<span style="FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="FONT-FAMILY: 宋体">：</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">1</span>
				<span style="FONT-FAMILY: 宋体">、声明相应的委托（正确声明很重要，否则不能调用成功，后面有详细介绍）。</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">2</span>
				<span style="FONT-FAMILY: 宋体">、加载</span>
				<span style="FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="FONT-FAMILY: 宋体">：</span>
		</div>
		<div>
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">int</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'"> hModule</span>
				<span style="FONT-FAMILY: 'Courier New'"> = <span style="COLOR: #2b91af">DLLWrapper</span>.<span style="COLOR: #030003">LoadLibrary</span>(<span style="COLOR: #030003">dllFilePath</span>);</span>
		</div>
		<div align="left">
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">if</span>
				<span style="FONT-FAMILY: 'Courier New'"> (<span style="COLOR: #030003">hModule</span> == 0)</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">return</span><span style="COLOR: blue">false</span>;</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">3</span>
				<span style="FONT-FAMILY: 宋体">、获取相应的委托实例：</span>
		</div>
		<div align="left">
				<span style="COLOR: #2b91af; FONT-FAMILY: 'Courier New'">FOO</span>
				<span style="FONT-FAMILY: 'Courier New'">
						<span style="COLOR: #030003">foo</span> = (<span style="COLOR: #2b91af">FOO</span>)<span style="COLOR: #2b91af">DLLWrapper</span>.<span style="COLOR: #030003">GetFunctionAddress</span>(<span style="COLOR: #030003">hModule</span>, <span style="COLOR: #a31515">"foo"</span>, <span style="COLOR: blue">typeof</span>(<span style="COLOR: #2b91af">FOO</span>));</span>
		</div>
		<div align="left">
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">if</span>
				<span style="FONT-FAMILY: 'Courier New'"> (<span style="COLOR: #030003">foo</span> == <span style="COLOR: blue">null</span>)</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">{</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: #2b91af">DLLWrapper</span>.<span style="COLOR: #030003">FreeLibrary</span>(<span style="COLOR: #030003">hModule</span>);</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">return</span><span style="COLOR: blue">false</span>;</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">}</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">4</span>
				<span style="FONT-FAMILY: 宋体">、调用函数：</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">foo(...);</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">5</span>
				<span style="FONT-FAMILY: 宋体">、</span>
				<span style="FONT-FAMILY: 'Courier New'">.NET</span>
				<span style="FONT-FAMILY: 宋体">并不能自动释放动态加载的</span>
				<span style="FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="FONT-FAMILY: 宋体">，因此我们在使用完</span>
				<span style="FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="FONT-FAMILY: 宋体">后应该自己释放</span>
				<span style="FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="FONT-FAMILY: 宋体">：</span>
		</div>
		<div>
				<span style="COLOR: #2b91af; FONT-FAMILY: 'Courier New'">DLLWrapper</span>
				<span style="FONT-FAMILY: 'Courier New'">.<span style="COLOR: #030003">FreeLibrary</span>(<span style="COLOR: #030003">hModule</span>);</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 宋体">下面我们将就委托应如何声明进行相应的讨论，在实际操作过程中，我发现使用</span>
				<span style="FONT-FAMILY: 'Courier New'">DllImport</span>
				<span style="FONT-FAMILY: 宋体">方法和动态调用方法两者在</span>
				<span style="FONT-FAMILY: 'Courier New'">C#</span>
				<span style="FONT-FAMILY: 宋体">中对</span>
				<span style="FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="FONT-FAMILY: 宋体">中函数原型的声明是有些区别的，下面我介绍动态调用中委托的声明：</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">1</span>
				<span style="FONT-FAMILY: 宋体">、首先应该注意的是，</span>
				<span style="FONT-FAMILY: 'Courier New'">C++</span>
				<span style="FONT-FAMILY: 宋体">中的类型和</span>
				<span style="FONT-FAMILY: 'Courier New'">C#</span>
				<span style="FONT-FAMILY: 宋体">中类型的对应关系，比如</span>
				<span style="FONT-FAMILY: 'Courier New'">C++</span>
				<span style="FONT-FAMILY: 宋体">中的</span>
				<span style="FONT-FAMILY: 'Courier New'">long</span>
				<span style="FONT-FAMILY: 宋体">应该对应</span>
				<span style="FONT-FAMILY: 'Courier New'">C#</span>
				<span style="FONT-FAMILY: 宋体">中的</span>
				<span style="FONT-FAMILY: 'Courier New'">Int32</span>
				<span style="FONT-FAMILY: 宋体">而不是</span>
				<span style="FONT-FAMILY: 'Courier New'">long</span>
				<span style="FONT-FAMILY: 宋体">，否则将导致调用结果出错。</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">2</span>
				<span style="FONT-FAMILY: 宋体">、结构的声明使用</span>
				<span>StructLayout对结构的相应布局进行设置，具体的请查看</span>
				<span>MSDN：</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 宋体">使用</span>
				<span style="FONT-FAMILY: 'Courier New'">LayoutKind</span>
				<span style="FONT-FAMILY: 宋体">指定结构中成员的布局顺序，一般可以使用</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">Sequential</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">：</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    [<span style="COLOR: #2b91af">StructLayout</span>(<span style="COLOR: #2b91af">LayoutKind</span>.<span style="COLOR: #030003">Sequential</span>)]</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">struct</span><span style="COLOR: #2b91af">StructVersionInfo</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    {</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span><span style="COLOR: #030003">MajorVersion</span>;</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span><span style="COLOR: #030003">MinorVersion</span>;</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">    }</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 宋体">另外，如果单独使用内部类型没有另外使用到字符串、结构、类，可以将结构在</span>
				<span style="FONT-FAMILY: 'Courier New'">C#</span>
				<span style="FONT-FAMILY: 宋体">中声明为</span>
				<span style="FONT-FAMILY: 'Courier New'">class</span>
				<span style="FONT-FAMILY: 宋体">：</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    [<span style="COLOR: #2b91af">StructLayout</span>(<span style="COLOR: #2b91af">LayoutKind</span>.<span style="COLOR: #030003">Sequential</span>)]</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">class</span><span style="COLOR: #2b91af">StructVersionInfo</span></span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    {</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span><span style="COLOR: #030003">MajorVersion</span>;</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span><span style="COLOR: #030003">MinorVersion</span>;</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">    }</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 宋体">对应</span>
				<span style="FONT-FAMILY: 'Courier New'">C++</span>
				<span style="FONT-FAMILY: 宋体">中的声明：</span>
		</div>
		<div align="left">
				<span style="COLOR: blue; FONT-FAMILY: 'Courier New'">    typedef</span>
				<span style="FONT-FAMILY: 'Courier New'">
						<span style="COLOR: blue">struct</span>
						<span style="COLOR: #030003">_VERSION_INFO</span>
				</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">    {</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">        <span style="COLOR: blue">int</span><span style="COLOR: #030003">MajorVersion</span>;</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">        <span style="COLOR: blue">int</span><span style="COLOR: #030003">MinorVersion</span>;</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">    }<span style="COLOR: #030003"> VERSION_INFO</span>, *<span style="COLOR: #030003">PVERSION_INFO</span>;</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 宋体">如果结构中使用到了字符串，最好应指定相应的字符集：</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">    </span>
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">[<span style="COLOR: #2b91af">StructLayout</span>(<span style="COLOR: #2b91af">LayoutKind</span>.<span style="COLOR: #030003">Sequential</span>,<span style="COLOR: #030003">CharSet</span>=<span style="COLOR: #2b91af">CharSet</span>.<span style="COLOR: #030003">Unicode</span>)]</span>
		</div>
		<div> </div>
		<div>
				<span style="FONT-FAMILY: 宋体">部分常用的声明对应关系（在结构中）：</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">C++</span>
				<span style="FONT-FAMILY: 宋体">：字符串数组</span>
		</div>
		<div>
				<span style="FONT-FAMILY: 'Courier New'">    </span>
				<span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">wchar_t</span>
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
						<span style="COLOR: #030003">Comments</span>[120];</span>
		</div>
		<div align="left">
				<span style="FONT-FAMILY: 'Courier New'">C#</span>
				<span style="FONT-FAMILY: 宋体">：</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">    [<span style="COLOR: #2b91af">MarshalAs</span>(<span style="COLOR: #2b91af">UnmanagedType</span>.<span style="COLOR: #030003">ByValTStr</span>, <span style="COLOR: #030003">SizeConst</span> = 120)]</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span><span style="COLOR: #030003">Comments</span>;</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">C++</span>
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体">：结构成员</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">VERSION_INFO</span></span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'"> ver;</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">C#</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">    </span>
				<span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">public</span>
				<span style="COLOR: #2b91af; FONT-FAMILY: 'Courier New'">StructVersionInfo </span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">ver;</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">C++</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">：函数指针声明</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">    </span>
				<span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">PFOO</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'"> pFoo; //</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">具体声明见文章前面部分</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">C#:</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">    </span>
				<span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">public</span>
				<span style="COLOR: #2b91af; FONT-FAMILY: 'Courier New'">IntPtr</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'"> pFoo; </span>
				<span style="COLOR: green; FONT-FAMILY: 'Courier New'">//</span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">也可以为</span>
				<span style="COLOR: green; FONT-FAMILY: 'Courier New'"> public int pFoo; </span>
		</div>
		<div align="left">
				<span style="COLOR: green; FONT-FAMILY: 'Courier New'">        //</span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">不同的声明方法可以使用上面</span>
				<span style="COLOR: green; FONT-FAMILY: 'Courier New'">DLLWrapper</span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">类的相应函数获取对应的委托实例</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">如果在结构中使用到了</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">union</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">，那么可以使用</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">FieldOffset</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">指定具体位置。</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">3</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">、委托的声明：</span>
		</div>
		<div align="left"> </div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">当</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">C++</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">编写的</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">函数需要通过指针传出将一个结构：如以下声明：</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">    </span>
				<span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">void</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'"> getVersionInfo(</span>
				<span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">VERSION_INFO</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'"> *ver);</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">对于在</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">C#</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">中声明为</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">class</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">的结构（当</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">VERSION_INFO</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">声明为</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">class</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">）</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">    </span>
				<span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">delegate void</span>
				<span style="COLOR: #2b91af; FONT-FAMILY: 'Courier New'">getVersionInfo</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">(</span>
				<span style="COLOR: #2b91af; FONT-FAMILY: 'Courier New'">VERSION_INFO</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'"> ver);</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">如果结构声明为</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">struct</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">，那么应该使用如下声明：</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">    </span>
				<span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">delegate void</span>
				<span style="COLOR: #2b91af; FONT-FAMILY: 'Courier New'">getVersionInfo</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">(</span>
				<span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">ref</span>
				<span style="COLOR: #2b91af; FONT-FAMILY: 'Courier New'">VERSION_INFO</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'"> ver);</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">注意：应该使用</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">ref</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">关键字。</span>
		</div>
		<div align="left"> </div>
		<div align="left"> </div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">如果</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">函数需要传入一个字符串，比如这样：</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">    BOOL</span>
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
						<span style="COLOR: blue">__stdcall</span> jingzhongrong1(<span style="COLOR: blue">const</span><span style="COLOR: blue">wchar_t</span>* <span style="COLOR: #030003">lpFileName</span>, <span style="COLOR: blue">int</span>* <span style="COLOR: #030003">FileNum</span>);</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">那么使用委托来调用函数的时候应该在</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">C#</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">中如下声明委托：</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">delegate</span><span style="COLOR: blue">bool</span><span style="COLOR: #2b91af">jingzhongrong1</span>(</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">       [<span style="COLOR: #2b91af">MarshalAs</span>(<span style="COLOR: #2b91af">UnmanagedType</span>.<span style="COLOR: #030003">LPWStr</span>)]<span style="COLOR: #2b91af">String</span><span style="COLOR: #030003">FileName</span>, </span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">ref</span><span style="COLOR: blue">int</span><span style="COLOR: #030003">FileNum</span>);</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">注意：应该使用</span>
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">[<span style="COLOR: #2b91af">MarshalAs</span>(<span style="COLOR: #2b91af">UnmanagedType</span>.<span style="COLOR: #030003">LPWStr</span>)]</span>
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体">和</span>
				<span style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: 'Courier New'">String</span>
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体">进行声明。</span>
		</div>
		<div align="left"> </div>
		<div align="left"> </div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">如果要在</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">DLL</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">函数中传出一个字符串，比如这样：</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">    void</span>
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
						<span style="COLOR: blue">__stdcall</span> jingzhongrong2(</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">wchar_t</span>* <span style="COLOR: #030003">lpFileName</span>, </span>
				<span style="COLOR: green; FONT-FAMILY: 'Courier New'">//</span>
				<span style="COLOR: green; FONT-FAMILY: 宋体">要传出的字符串</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">int</span>* <span style="COLOR: #030003">Length</span>);</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">那么我们如下声明委托：</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">    <span style="COLOR: green">//</span></span>
				<span style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 宋体">使用委托从非托管函数的参数中传出的字符串，</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">    <span style="COLOR: green">//</span></span>
				<span style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 宋体">应该这样声明，并在调用前为</span>
				<span style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 'Courier New'">StringBuilder</span>
				<span style="FONT-SIZE: 10pt; COLOR: green; FONT-FAMILY: 宋体">预备足够的空间</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">    <span style="COLOR: blue">delegate</span><span style="COLOR: blue">void</span><span style="COLOR: #2b91af">jingzhongrong2</span>(</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">       [<span style="COLOR: #2b91af">MarshalAs</span>(<span style="COLOR: #2b91af">UnmanagedType</span>.<span style="COLOR: #030003">LPWStr</span>)] <span style="COLOR: #2b91af">StringBuilder</span><span style="COLOR: #030003">lpFileName</span>,</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">       <span style="COLOR: blue">ref</span><span style="COLOR: blue">int</span><span style="COLOR: #030003">Length</span>,</span>
		</div>
		<div align="left">
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">    );</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">在使用函数前，应先为</span>
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">StringBuilder</span>
				<span style="COLOR: #030003; FONT-FAMILY: 宋体">声明足够的空间用于存放字符串：</span>
		</div>
		<div align="left">
				<span style="COLOR: #030003; FONT-FAMILY: 'Courier New'">    </span>
				<span style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: 'Courier New'">StringBuilder</span>
				<span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
						<span style="COLOR: #030003">fileName</span> = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">StringBuilder</span>(<span style="COLOR: #030003">FileNameLength</span>);</span>
		</div>
<img src ="http://www.blogjava.net/Yipak/aggbug/226313.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Yipak/" target="_blank">死神</a> 2008-09-02 11:56 <a href="http://www.blogjava.net/Yipak/articles/226313.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C#中HashTable的用法</title><link>http://www.blogjava.net/Yipak/articles/CSharp.html</link><dc:creator>死神</dc:creator><author>死神</author><pubDate>Thu, 28 Aug 2008 09:17:00 GMT</pubDate><guid>http://www.blogjava.net/Yipak/articles/CSharp.html</guid><wfw:comment>http://www.blogjava.net/Yipak/comments/225353.html</wfw:comment><comments>http://www.blogjava.net/Yipak/articles/CSharp.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Yipak/comments/commentRss/225353.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Yipak/services/trackbacks/225353.html</trackback:ping><description><![CDATA[
		<div class="postText">
				<p>
						<font size="2">一,哈希表(Hashtable)简述</font>
				</p>
				<p>
						<font size="2">  在.NET Framework中，Hashtable是System.Collections命名空间提供的一个容器，用于处理和表现类似keyvalue的键值对，其中key通常可用来快速查找，同时key是区分大小写；value用于存储对应于key的值。Hashtable中keyvalue键值对均为object类型，所以Hashtable可以支持任何类型的keyvalue键值对.</font>
				</p>
				<p>
						<font size="2">二,哈希表的简单操作</font>
				</p>
				<p>
						<font size="2"> 在哈希表中添加一个keyvalue键值对：HashtableObject.Add(key,value);<br /> 在哈希表中去除某个keyvalue键值对：HashtableObject.Remove(key);<br /> 从哈希表中移除所有元素：           HashtableObject.Clear(); <br /> 判断哈希表是否包含特定键key：      HashtableObject.Contains(key);<br /> 下面控制台程序将包含以上所有操作：<br />using System;<br />using System.Collections; file使用Hashtable时，必须引入这个命名空间<br />class hashtable<br />{<br />  public static void Main()<br />  {<br />  Hashtable ht=new Hashtable(); file创建一个Hashtable实例<br />  ht.Add(E,e);添加keyvalue键值对<br />  ht.Add(A,a);<br />  ht.Add(C,c);<br />  ht.Add(B,b);</font>
				</p>
				<p>
						<font size="2">  string s=(string)ht[A];<br />  if(ht.Contains(E)) file判断哈希表是否包含特定键,其返回值为true或false<br />    Console.WriteLine(the E keyexist);<br />  ht.Remove(C);移除一个keyvalue键值对<br />  Console.WriteLine(ht[A]);此处输出a<br />  ht.Clear();移除所有元素<br />  Console.WriteLine(ht[A]); file此处将不会有任何输出<br />  }<br />}</font>
				</p>
				<p>
						<font size="2">三,遍历哈希表</font>
				</p>
				<p>
						<font size="2"> 遍历哈希表需要用到DictionaryEntry Object，代码如下：<br /> for(DictionaryEntry de in ht) fileht为一个Hashtable实例<br /> {<br />   Console.WriteLine(de.Key);de.Key对应于keyvalue键值对key<br />   Console.WriteLine(de.Value);de.Key对应于keyvalue键值对value<br /> }</font>
				</p>
				<p>
						<font size="2">四,对哈希表进行排序</font>
				</p>
				<p>
						<font size="2">  对哈希表进行排序在这里的定义是对keyvalue键值对中的key按一定规则重新排列，但是实际上这个定义是不能实现的，因为我们无法直接在Hashtable进行对key进行重新排列，如果需要Hashtable提供某种规则的输出，可以采用一种变通的做法：<br /> ArrayList akeys=new ArrayList(ht.Keys); file别忘了导入System.Collections<br /> akeys.Sort(); file按字母顺序进行排序<br /> for(string skey in akeys)<br /> {<br />   Console.Write(skey + );<br />   Console.WriteLine(ht[skey]);排序后输出<br /> }<br /><br /><br />补充： </font>
						<font size="3">HashTable 的值也可以是一个集合，HashTable中可以存放任何对象. 所对应的Key,Value都是对应的对象类型. 比如说HashTable里还能放HashTable. <br /></font>
				</p>
		</div>
<img src ="http://www.blogjava.net/Yipak/aggbug/225353.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Yipak/" target="_blank">死神</a> 2008-08-28 17:17 <a href="http://www.blogjava.net/Yipak/articles/CSharp.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>