<?xml version="1.0" encoding="gb2312"?>
<rss version="2.0">
<channel>
<title><![CDATA[星空地带]]></title>
        <image>
        <title>http://hi.baidu.com</title>
        <link>http://hi.baidu.com</link>
        <url>http://img.baidu.com/img/logo-hi.gif</url>
        </image>
<description><![CDATA[这里是知识的海洋,也是疯狂的天地.]]></description>
<link>http://hi.baidu.com/miskkk</link>
<language>zh-cn</language>
<generator>www.baidu.com</generator>
<ttl>5</ttl>


<item>
        <title><![CDATA[判断是否英文字母或数字的C#正则表达式（转)]]></title>
        <link><![CDATA[http://hi.baidu.com/miskkk/blog/item/b18594127dbf38c6c3fd7886.html]]></link>
        <description><![CDATA[
		
		<div class="cnt">
<p><font face="Courier New">定义一个公有的方法，判断传入的字符是否是英文字母或数字</font></p>
<p><font face="Courier New">&nbsp;&nbsp;  public bool IsNatural_Number(string str)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  System.Text.RegularExpressions.Regex reg1 = new  System.Text.RegularExpressions.Regex(@&quot;^[A-Za-z0-9]+$&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  return reg1.IsMatch(str);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }</font></p>
<p><font face="Courier New">定义一个公有的方法，判断传入的字符是否是数字</font></p>
<p><font face="Courier New">&nbsp;&nbsp;&nbsp;  public bool Is_Number(string str)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@&quot;^[0-9]+$&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  return reg1.IsMatch(str);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
</font></p>
</div> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/miskkk/blog/category/c%23">c#</a>&nbsp;<a href="http://hi.baidu.com/miskkk/blog/item/b18594127dbf38c6c3fd7886.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-11  08:39</pubDate>
        <category><![CDATA[c#]]></category>
        <author><![CDATA[shellshi]]></author>
		<guid>http://hi.baidu.com/miskkk/blog/item/b18594127dbf38c6c3fd7886.html</guid>
</item>

<item>
        <title><![CDATA[用Visual C＃做DLL文件]]></title>
        <link><![CDATA[http://hi.baidu.com/miskkk/blog/item/61bef907e4ce1ec57b8947b7.html]]></link>
        <description><![CDATA[
		
		作为软件设计和开发人员大都有过使用DLL（动态连接库）的经历，DLL的产生使得我们的应用程序在可维护性、代码的重复使用等方面都有了很大的提高。以前用的DLL一般都是用Visual C++、Delphi或者VB等编程语言来编写的，这种DLL的编写和使用，我们大都已经比较习惯了。作为新一代的程序开发语言--Visual C#，到底是如何编写和使用DLL的呢！本文就试着就这方面的问题来进行简单的介绍。<br>
<br>
　　Visual C++、Delphi或者VB等编程语言来编写成的DLL文件，在编译完成过以后，产生DLL文件已经是一个可以直接供计算机使用的二进制文件。但用Visual C#编译器生成的受管代码（managed code）虽然也是二进制文件，但不是可以直接供计算机使用的原始代码（机器语言代码）。他实质上是一种中间语言（IL）代码，这种IL代码要转变成可以供计算机直接使用的原始代码，就需要经过&quot;下一代窗口服务&quot;( Next Generation Windows Services,简写为NGWS ) runtime的即时编译器（即JIT）进行编译。<br>
<br>
　　经过以上比较，我们可以看出，用Visual C#生成的DLL文件已经和以前的DLL文件有了本质上的区别。用Visual C#生成的DLL文件在程序设计中更多的表现为一种类（Class）或者类库（Class Library）。本文就试着通过一个具体程序的例子，按照下面步骤来具体介绍：<br>
<br>
　　（1）.创建一个DLL源代码。<br>
<br>
　　（2）.编译此DLL源代码，生成DLL文件。<br>
<br>
　　（3）.用此DLL来创建一个简单的客户端程序。<br>
<br>
　　<strong><font color="#ac0000">一. 程序设计开发及运行环境</font></strong>：<br>
<br>
　　（1）.微软视窗2000专业版<br>
<br>
　　（2）..Net FrameWork SDK Beta 2<br>
<br>
　　<strong><font color="#ac0000">二. 创建一个DLL源代码（dll.cs）</font></strong><br>
<br>
　　由于用Visual C#创建的DLL，此DLL是不需要执行的界面，所以在DLL文件就没有必要定义Main ( )函数，来作为应用程序执行的入口。Dll.cs的源程序代码如下：<br>
<br>
　　Dll.cs：<br>
<br>
<table class="FCK__ShowTableBorders" width="600" align="center" bgcolor="#ffffff" border="0">
    <tbody>
        <tr>
            <td>namespace Dll file://定义了名称空间，在调用DLL的时候就要导入此名称空间。<br>
            {<br>
            　public class Show file://定义了一个类，在程序中就要来继承此类。<br>
            　{　<br>
            　　public string Messages ( ) <br>
            　　file://定义了一个方法，此方法的作用就是返回下面字符串。<br>
            　　{<br>
            　　　return &quot;欢迎使用Visual C#做的DLL文件！&quot; ;<br>
            　　}<br>
            　}<br>
            }</td>
        </tr>
    </tbody>
</table>
<br>
　　通过此DLL的源程序可以看出，此DLL表现为一个小型的类库，这是因为在此DLL中封装了名字叫DLL的名称空间，在此名称空间中又定义了一个Show类，在此类中有一个方法就是Messages。虽然定义的内容相对少了些，但却相当完全。<br>
<strong><font color="#ac0000">三. 编译此DLL源代码，生成DLL文件<br>
<br>
</font></strong>　　要把DLL源代码编译成DLL文件，就需要配置好编译器Csc.exe的参数和开关。我们知道编译器Csc.exe可以把源代码编译成四种不同的文件，分别是控制应用程序、代码库、windows应用程序、模块程序。编译命令具体如下：<br>
<br>
<table class="FCK__ShowTableBorders" width="600" align="center" bgcolor="#ffffff" border="0">
    <tbody>
        <tr>
            <td>csc /target:exe myProj.cs // 创建一个myProj.exe控制程序<br>
            csc /target:winexe myProject.cs file://创建一个myProj.exe的windows程序<br>
            csc /target:library myProject.cs file://创建一个myProj.dll代码库<br>
            csc /target:module myProject.cs file://创建一个myProj.dll模块</td>
        </tr>
    </tbody>
</table>
<br>
　　对于如何配置编译器Csc.exe的其他参数和开关，可以参考稍前发表的文章《如何用CSC.exe来编译Visual C#的代码文件》，在此篇文章里面有比较详细的介绍。通过以下编译命令可以得到mydll.dll文件：<br>
<br>
<table class="FCK__ShowTableBorders" width="600" align="center" bgcolor="#ffffff" border="0">
    <tbody>
        <tr>
            <td>Csc /r:system.dll /t:library /out:mydll.dll dll.cs</td>
        </tr>
    </tbody>
</table>
<br>
　　<strong><font color="#ac0000">四．用此DLL来创建一个简单的客户端程序（test.exe）</font></strong><br>
<br>
　　通过以上的源程序代码可以看到生成的mydll.dll文件虽然是一个以DLL为扩展名，实际上是一个类库，和我们经常用到的System.dll、System.Windows.Forms.dll等这些文件相似。同样用mydll.dll创建程序也和用以上这些类库创建程序相类似。就是第一步就是导入此名称空间--Dll。然后在去继承里面封装好的类--Show，再调用类中定义好的方法--Messages。下面就是按照以上的步骤，创建的客户端的源程序代码( test.cs ) ：<br>
<br>
<table class="FCK__ShowTableBorders" width="600" align="center" bgcolor="#ffffff" border="0">
    <tbody>
        <tr>
            <td>test.cs:<br>
            using Dll ; // 导入此名称空间<br>
            using System ;<br>
            <br>
            public class GetMessage<br>
            {<br>
            　public static void Main ( )<br>
            　{<br>
            　　Show hi = new Show ( ) ; // 继承名称空间中定义的Show类<br>
            　　Console.WriteLine ( hi.Messages ( ) ) ; // 调用此类中的方法<br>
            　}<br>
            }</td>
        </tr>
    </tbody>
</table>
<br>
　　在把test.cs编译成执行程序中，要在编译命令中添加一个引用，就是引用mydll.dll文件。具体的编译命令如下：<br>
<br>
<table class="FCK__ShowTableBorders" width="600" align="center" bgcolor="#ffffff" border="0">
    <tbody>
        <tr>
            <td>csc /r:mydll.dll /r:system.dll test.cs</td>
        </tr>
    </tbody>
</table>
<br>
　　编译完成，就会生成test.exe。执行此文件就会得到以下执行界面：<br>
<div forimg="1">
<div forimg="1">
<div forimg="1"><img class="blogimg" src="http://hiphotos.baidu.com/clbd_control/pic/item/3fce0d5188a2da09377abec7.jpg" border="0" small="0"></div>
</div>
<strong><font color="#ac0000">五.总结</font></strong>：<br>
<br>
　　通过此篇文章，可以看出用Visual C#制作一个DLL其实并不是一件很复杂的事件，但对DLL的调用却和以往有了较大区别，其中最主要的原因是，用Visual C#或者其他.Net 程序开发语言制作的DLL和以前的DLL有了实质上的区别。它已经不是严格意义上的动态连接库了，而是一个类或者类库。</div> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/miskkk/blog/category/c%23">c#</a>&nbsp;<a href="http://hi.baidu.com/miskkk/blog/item/61bef907e4ce1ec57b8947b7.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-09  22:35</pubDate>
        <category><![CDATA[c#]]></category>
        <author><![CDATA[shellshi]]></author>
		<guid>http://hi.baidu.com/miskkk/blog/item/61bef907e4ce1ec57b8947b7.html</guid>
</item>

<item>
        <title><![CDATA[讲故事谈.NET委托:一个C#睡前故事3]]></title>
        <link><![CDATA[http://hi.baidu.com/miskkk/blog/item/068a1729abde18f699250aae.html]]></link>
        <description><![CDATA[
		
		<div class="art_area mt10">
<p> </p>
<h4>事件</h4>
<p>　　不幸的是，宇宙太忙了，也不习惯时刻关注它里面的个体，它可以用自己的委托替换了彼得老板的委托。这是把彼得的Worker类的的委托字段做成public的一个无意识的副作用。同样，如果彼得的老板不耐烦了，也可以决定自己来激发彼得的委托（真是一个粗鲁的老板）：</p>
<p>// Peter's boss taking matters into his own hands<br>
if( peter.completed != null ) peter.completed();</p>
<p>　　彼得不想让这些事发生，他意识到需要给每个委托提供&ldquo;注册&rdquo;和&ldquo;反注册&rdquo;功能，这样监听者就可以自己添加和移除委托，但同时又不能清空整个列表也不能随意激发彼得的事件了。彼得并没有来自己实现这些功能，相反，他使用了event关键字让C#编译器为他构建这些方法：</p>
<p class="code">class Worker {<br>
...<br>
&nbsp;&nbsp;&nbsp;  public event WorkStarted started;<br>
&nbsp;&nbsp;&nbsp;  public event WorkProgressing progressing;<br>
&nbsp;&nbsp;&nbsp;  public event WorkCompleted completed;<br>
}</p>
<p>　　彼得知道event关键字在委托的外边包装了一个property，仅让C#客户通过+= 和 -=操作符来添加和移除，强迫他的老板和宇宙正确地使用事件。</p>
<p class="code">static void Main() {<br>
&nbsp;&nbsp;&nbsp;  Worker peter = new Worker();<br>
&nbsp;&nbsp;&nbsp;  Boss boss = new Boss();<br>
&nbsp;&nbsp;&nbsp;  peter.completed += new WorkCompleted(boss.WorkCompleted);<br>
&nbsp;&nbsp;&nbsp;  peter.started += new WorkStarted(Universe.WorkerStartedWork);<br>
&nbsp;&nbsp;&nbsp;  peter.completed += new WorkCompleted(Universe.WorkerCompletedWork);<br>
&nbsp;&nbsp;&nbsp;  peter.DoWork();<br>
<br>
&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;Main: 工人工作完成&rdquo;);<br>
&nbsp;&nbsp;&nbsp;  Console.ReadLine();<br>
}</p>
<h4>&ldquo;收获&rdquo;所有结果</h4>
<p>　　到这时，彼得终于可以送一口气了，他成功地满足了所有监听者的需求，同时避免了与特定实现的紧耦合。但是他注意到他的老板和宇宙都为它的工作打了分，但是他仅仅接收了一个分数。面对多个监听者，他想要&ldquo;收获&rdquo;所有的结果，于是他深入到代理里面，轮询监听者列表，手工一个个调用：</p>
<p class="code">public void DoWork() {<br>
&nbsp;&nbsp;&nbsp;  ...<br>
&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;&ldquo;工作: 工作完成&rdquo;&quot;);<br>
&nbsp;&nbsp;&nbsp;  if( completed != null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  foreach( WorkCompleted wc in completed.GetInvocationList() ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  int grade = wc();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工人的工作得分＝&rdquo; + grade);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;  }<br>
}</p>
<p> </p>
</div>
<div class="art_adv_text"><span>
<div class="art_area mt10">
<p> </p>
<h4>异步通知：激发 &amp; 忘掉</h4>
<p>　　同时，他的老板和宇宙还要忙于处理其他事情，也就是说他们给彼得打分所花费的事件变得非常长：</p>
<p class="code">class Boss {<br>
&nbsp;&nbsp;&nbsp;  public int WorkCompleted() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  System.Threading.Thread.Sleep(3000);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;Better...&quot;); return 6; /* 总分为10 */<br>
&nbsp;&nbsp;&nbsp;  }<br>
}<br>
<br>
class Universe {<br>
&nbsp;&nbsp;&nbsp;  static int WorkerCompletedWork() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  System.Threading.Thread.Sleep(4000);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;Universe is pleased with worker's work&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  return 7;<br>
&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;  ...<br>
}</p>
<p>　　很不幸，彼得每次通知一个监听者后必须等待它给自己打分，现在这些通知花费了他太多的工作事件。于是他决定忘掉分数，仅仅异步激发事件：</p>
<p class="code">public void DoWork() {<br>
&nbsp;&nbsp;&nbsp;  ...<br>
&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;&ldquo;工作: 工作完成&rdquo;&quot;);<br>
&nbsp;&nbsp;&nbsp;  if( completed != null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  foreach( WorkCompleted wc in completed.GetInvocationList() )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  wc.BeginInvoke(null, null);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;  }<br>
}</p>
<h4>异步通知：轮询</h4>
<p>　　这使得彼得可以通知他的监听者，然后立即返回工作，让进程的线程池来调用这些代理。随着时间的过去，彼得发现他丢失了他工作的反馈，他知道听取别人的赞扬和努力工作一样重要，于是他异步激发事件，但是周期性地轮询，取得可用的分数。</p>
<p class="code">public void DoWork() {<br>
&nbsp;&nbsp;&nbsp;  ...<br>
&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;&ldquo;工作: 工作完成&rdquo;&quot;);<br>
&nbsp;&nbsp;&nbsp;  if( completed != null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  foreach( WorkCompleted wc in completed.GetInvocationList() ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  IAsyncResult res = wc.BeginInvoke(null, null);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  while( !res.IsCompleted ) System.Threading.Thread.Sleep(1);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  int grade = wc.EndInvoke(res);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工人的工作得分＝&rdquo; + grade);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;  }<br>
}</p>
<h4>异步通知：委托</h4>
<p>　　不幸地，彼得有回到了一开始就想避免的情况中来，比如，老板站在背后盯着他工作。于是，他决定使用自己的委托作为他调用的异步委托完成的通知，让他自己立即回到工作，但是仍可以在别人给他的工作打分后得到通知：</p>
<p class="code">&nbsp;&nbsp;&nbsp;  public void DoWork() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  ...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;&ldquo;工作: 工作完成&rdquo;&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  if( completed != null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  foreach( WorkCompleted wc in completed.GetInvocationList() ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  wc.BeginInvoke(new AsyncCallback(WorkGraded), wc);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;  }<br>
<br>
&nbsp;&nbsp;&nbsp;  private void WorkGraded(IAsyncResult res) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  WorkCompleted wc = (WorkCompleted)res.AsyncState;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  int grade = wc.EndInvoke(res);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工人的工作得分＝&rdquo; + grade);<br>
&nbsp;&nbsp;&nbsp;  }</p>
<h4>宇宙中的幸福</h4>
<p>　　彼得、他的老板和宇宙最终都满足了。彼得的老板和宇宙可以收到他们感兴趣的事件通知，减少了实现的负担和非必需的往返&ldquo;差旅费&rdquo;。彼得可以通知他们，而不管他们要花多长时间来从目的方法中返回，同时又可以异步地得到他的结果。彼得知道，这并不*十分*简单，因为当他异步激发事件时，方法要在另外一个线程中执行，彼得的目的方法完成的通知也是一样的道理。但是，迈克和彼得是好朋友，他很熟悉线程的事情，可以在这个领域提供指导。</p>
<p>　　他们永远幸福地生活下去……&lt;完&gt;</p>
</div>
</span>

</div> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/miskkk/blog/category/%C4%AC%C8%CF%B7%D6%C0%E0">默认分类</a>&nbsp;<a href="http://hi.baidu.com/miskkk/blog/item/068a1729abde18f699250aae.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-09  22:22</pubDate>
        <category><![CDATA[默认分类]]></category>
        <author><![CDATA[shellshi]]></author>
		<guid>http://hi.baidu.com/miskkk/blog/item/068a1729abde18f699250aae.html</guid>
</item>

<item>
        <title><![CDATA[讲故事谈.NET委托:一个C#睡前故事2]]></title>
        <link><![CDATA[http://hi.baidu.com/miskkk/blog/item/275d8a86633d873667096ead.html]]></link>
        <description><![CDATA[
		
		<div class="art_area mt10">
<p> </p>
<h4>委托</h4>
<p>　　不幸的是，每当彼得忙于通过接口的实现和老板交流时，就没有机会及时通知宇宙了。至少他应该忽略身在远方的老板的引用，好让其他实现了IWorkerEvents的对象得到他的工作报告。（&rdquo;At least he'd abstracted the reference of his boss far away from him so that others who implemented the IWorkerEvents interface could be notified of his work progress&rdquo; 原话如此，不理解到底是什么意思 ）</p>
<p>　　他的老板还是抱怨得很厉害。&ldquo;彼得！&rdquo;他老板吼道，&ldquo;你为什么在工作一开始和工作进行中都来烦我？！我不关心这些事件。你不但强迫我实现了这些方法，而且还在浪费我宝贵的工作时间来处理你的事件，特别是当我外出的时候更是如此！你能不能不再来烦我？&rdquo;</p>
<p>　　于是，彼得意识到接口虽然在很多情况都很有用，但是当用作事件时，&ldquo;粒度&rdquo;不够好。他希望能够仅在别人想要时才通知他们，于是他决定把接口的方法分离为单独的委托，每个委托都像一个小的接口方法：</p>
<p class="code">delegate void WorkStarted();<br>
delegate void WorkProgressing();<br>
delegate int WorkCompleted();<br>
<br>
class Worker {<br>
&nbsp;&nbsp;&nbsp;  public void DoWork() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工作: 工作开始&rdquo;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  if( started != null ) started();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工作: 工作进行中&rdquo;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  if( progressing != null ) progressing();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;&ldquo;工作: 工作完成&rdquo;&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  if( completed != null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  int grade = completed();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工人的工作得分＝&rdquo; + grade);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;  public WorkStarted started;<br>
&nbsp;&nbsp;&nbsp;  public WorkProgressing progressing;<br>
&nbsp;&nbsp;&nbsp;  public WorkCompleted completed;<br>
}<br>
<br>
class Boss {<br>
&nbsp;&nbsp;&nbsp;  public int WorkCompleted() {<br>
&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;Better...&quot;);<br>
&nbsp;&nbsp;&nbsp;  return 4; /* 总分为10 */<br>
}<br>
}<br>
<br>
class Universe {<br>
&nbsp;&nbsp;&nbsp;  static void Main() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Worker peter = new Worker();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Boss boss = new Boss();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  peter.completed = new WorkCompleted(boss.WorkCompleted);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  peter.DoWork();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;Main: 工人工作完成&rdquo;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.ReadLine();<br>
&nbsp;&nbsp;&nbsp;  }<br>
}</p>
<h4>静态监听者</h4>
<p>　　这样，彼得不会再拿他老板不想要的事件来烦他老板了，但是他还没有把宇宙放到他的监听者列表中。因为宇宙是个包涵一切的实体，看来不适合使用实例方法的委托（想像一下，实例化一个&ldquo;宇宙&rdquo;要花费多少资源…..），于是彼得就需要能够对静态委托进行挂钩，委托对这一点支持得很好：</p>
<p class="code">class Universe {<br>
&nbsp;&nbsp;&nbsp;  static void WorkerStartedWork() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;Universe notices worker starting work&quot;);<br>
&nbsp;&nbsp;&nbsp;  }<br>
<br>
&nbsp;&nbsp;&nbsp;  static int WorkerCompletedWork() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;Universe pleased with worker's work&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  return 7;<br>
&nbsp;&nbsp;&nbsp;  }<br>
<br>
&nbsp;&nbsp;&nbsp;  static void Main() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Worker peter = new Worker();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Boss boss = new Boss();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  peter.completed = new WorkCompleted(boss.WorkCompleted);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  peter.started = new WorkStarted(Universe.WorkerStartedWork);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  peter.completed = new WorkCompleted(Universe.WorkerCompletedWork);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  peter.DoWork();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;Main: 工人工作完成&rdquo;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.ReadLine();<br>
&nbsp;&nbsp;&nbsp;  }<br>
}</p>
<p> </p>
</div> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/miskkk/blog/category/c%23">c#</a>&nbsp;<a href="http://hi.baidu.com/miskkk/blog/item/275d8a86633d873667096ead.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-09  22:21</pubDate>
        <category><![CDATA[c#]]></category>
        <author><![CDATA[shellshi]]></author>
		<guid>http://hi.baidu.com/miskkk/blog/item/275d8a86633d873667096ead.html</guid>
</item>

<item>
        <title><![CDATA[讲故事谈.NET委托:一个C#睡前故事1]]></title>
        <link><![CDATA[http://hi.baidu.com/miskkk/blog/item/cbf878fb97d1bb1e6d22ebad.html]]></link>
        <description><![CDATA[
		
		<p>从前，在南方一块奇异的土地上，有个工人名叫彼得，他非常勤奋，对他的老板总是百依百顺。但是他的老板是个吝啬的人，从不信任别人，坚决要求随时知道彼得的工作进度，以防止他偷懒。但是彼得又不想让老板呆在他的办公室里站在背后盯着他，于是就对老板做出承诺：无论何时，只要我的工作取得了一点进展我都会及时让你知道。彼得通过周期性地使用&ldquo;带类型的引用&rdquo;(原文为：&ldquo;typed reference&rdquo; 也就是delegate？？)&ldquo;回调&rdquo;他的老板来实现他的承诺，如下：</p>
<p class="code">class Worker {<br>
&nbsp;&nbsp;&nbsp;  public void Advise(Boss boss) { _boss = boss; }<br>
&nbsp;&nbsp;&nbsp;  public void DoWork() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工作: 工作开始&rdquo;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  if( _boss != null ) _boss.WorkStarted();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工作: 工作进行中&rdquo;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  if( _boss != null ) _boss.WorkProgressing();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;&ldquo;工作: 工作完成&rdquo;&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  if( _boss != null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  int grade = _boss.WorkCompleted();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工人的工作得分＝&rdquo; + grade);<br>
&nbsp;&nbsp;&nbsp;  }<br>
}<br>
private Boss _boss;<br>
}<br>
<br>
class Boss {<br>
&nbsp;&nbsp;&nbsp;  public void WorkStarted() { /* 老板不关心。 */ }<br>
&nbsp;&nbsp;&nbsp;  public void WorkProgressing() { /*老板不关心。 */ }<br>
&nbsp;&nbsp;&nbsp;  public int WorkCompleted() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;时间差不多！&rdquo;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  return 2; /* 总分为10 */<br>
&nbsp;&nbsp;&nbsp;  }<br>
}<br>
<br>
class Universe {<br>
&nbsp;&nbsp;&nbsp;  static void Main() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Worker peter = new Worker();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Boss boss = new Boss();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  peter.Advise(boss);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  peter.DoWork();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;Main: 工人工作完成&rdquo;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.ReadLine();<br>
&nbsp;&nbsp;&nbsp;  }<br>
}</p>
<h4>接口</h4>
<p>　　现在，彼得成了一个特殊的人，他不但能容忍吝啬的老板，而且和他周围的宇宙也有了密切的联系，以至于他认为宇宙对他的工作进度也感兴趣。不幸的是，他必须也给宇宙添加一个特殊的回调函数Advise来实现同时向他老板和宇宙报告工作进度。彼得想要把潜在的通知的列表和这些通知的实现方法分离开来，于是他决定把方法分离为一个接口：</p>
<p class="code">interface IWorkerEvents {<br>
&nbsp;&nbsp;&nbsp;  void WorkStarted();<br>
&nbsp;&nbsp;&nbsp;  void WorkProgressing();<br>
&nbsp;&nbsp;&nbsp;  int WorkCompleted();<br>
}<br>
<br>
class Worker {<br>
&nbsp;&nbsp;&nbsp;  public void Advise(IWorkerEvents events) { _events = events; }<br>
&nbsp;&nbsp;&nbsp;  public void DoWork() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工作: 工作开始&rdquo;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  if( _events != null ) _events.WorkStarted();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工作: 工作进行中&rdquo;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  if(_events != null ) _events.WorkProgressing();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;&ldquo;工作: 工作完成&rdquo;&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  if(_events != null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  int grade = _events.WorkCompleted();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;工人的工作得分＝&rdquo; + grade);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;  private IWorkerEvents _events;<br>
}<br>
<br>
class Boss : IWorkerEvents {<br>
&nbsp;&nbsp;&nbsp;  public void WorkStarted() { /* 老板不关心。 */ }<br>
&nbsp;&nbsp;&nbsp;  public void WorkProgressing() { /* 老板不关心。 */ }<br>
&nbsp;&nbsp;&nbsp;  public int WorkCompleted() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&ldquo;时间差不多！&rdquo;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  return 3; /* 总分为10 */<br>
&nbsp;&nbsp;&nbsp;  }<br>
}</p>
<p> </p>
<div class="art_adv_text">

</div> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/miskkk/blog/category/c%23">c#</a>&nbsp;<a href="http://hi.baidu.com/miskkk/blog/item/cbf878fb97d1bb1e6d22ebad.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-09  22:20</pubDate>
        <category><![CDATA[c#]]></category>
        <author><![CDATA[shellshi]]></author>
		<guid>http://hi.baidu.com/miskkk/blog/item/cbf878fb97d1bb1e6d22ebad.html</guid>
</item>

<item>
        <title><![CDATA[c# 相对路径 獲取]]></title>
        <link><![CDATA[http://hi.baidu.com/miskkk/blog/item/3f82523ec9443f3570cf6c88.html]]></link>
        <description><![CDATA[
		
		  string   str1   =Process.GetCurrentProcess().MainModule.FileName;//可获得当前执行的exe的文件名。       <br>
  string   str2=Environment.CurrentDirectory;//获取和设置当前目录（即该进程从中启动的目录）的完全限定路径。   <br>
<clk style="font-size: 12px"></clk>  //备注   按照定义，如果该进程在本地或<nobr style="font-size: 12px; color: #6600ff; border-bottom: #6600ff 1px dotted; background-color: transparent; text-decoration: underline" >网络</nobr>驱动器的根目录中启动，则此属性的值为驱动器名称后跟一个尾部反斜杠（如&ldquo;C:\&rdquo;）。如果该进程在子目录中启动，则此属性的值为不带尾部反斜杠的驱动器和子目录路径（如&ldquo;C:\mySubDirectory&rdquo;）。   <br>
  string   str3=Directory.GetCurrentDirectory();//获取应用程序的当前工作目录。   <br>
  string   str4=AppDomain.CurrentDomain.BaseDirectory;//获取基目录，它由程序集冲突解决程序用来探测程序集。   <br>
  string   str5=Application.StartupPath;//获取启动了应用程序的可执行文件的路径，不包括可执行文件的名称。   <br>
  string   str6=Application.ExecutablePath;//获取启动了应用程序的可执行文件的路径，包括可执行文件的名称。   <br>
  string   str7=AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//获取或设置包含该应用程序的目录的名称。 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/miskkk/blog/category/c%23">c#</a>&nbsp;<a href="http://hi.baidu.com/miskkk/blog/item/3f82523ec9443f3570cf6c88.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-09  10:40</pubDate>
        <category><![CDATA[c#]]></category>
        <author><![CDATA[shellshi]]></author>
		<guid>http://hi.baidu.com/miskkk/blog/item/3f82523ec9443f3570cf6c88.html</guid>
</item>

<item>
        <title><![CDATA[asp.net调用存储过程方法新解]]></title>
        <link><![CDATA[http://hi.baidu.com/miskkk/blog/item/faa6aa44d53dee44500ffe00.html]]></link>
        <description><![CDATA[
		
		在使用.net的过程中，数据库访问是一个很重要的部分，特别是在b/s系统的构建过程中，数据库操作几乎成为了一个必不可少的操作。调用<a class="article" href="http://www.enet.com.cn/solution/" target="_blank">存储</a>过程实现数据库操作使很多程序员使用的方法，而且大多数的程序员都是能使用存储过程就使用存储过程，很少直接使用sql语句，所以存储过程是很有用而且很重要的。 <br>
<br>
　　<strong>存储过程简介</strong> <br>
<br>
　　简单的说，存储过程是由一些sql语句和控制语句组成的被封装起来的过程，它驻留在数据库中，可以被客户应用程序调用，也可以从另一个过程或触发器调用。它的参数可以被传递和返回。与应用程序中的函数过程类似，存储过程可以通过名字来调用，而且它们同样有输入参数和输出参数。 <br>
<br>
　　根据返回值类型的不同，我们可以将存储过程分为三类：返回记录集的存储过程， 返回数值的存储过程（也可以称为标量存储过程），以及行为存储过程。顾名思义，返回记录集的存储过程的执行结果是一个记录集，典型的例子是从数据库中检索出符合某一个或几个条件的记录；返回数值的存储过程执行完以后返回一个值，例如在数据库中执行一个有返回值的函数或命令；最后，行为存储过程仅仅是用来实现数据库的某个功能，而没有返回值，例如在数据库中的更新和删除操作。 <br>
<br>
　　<strong>使用存储过程的好处</strong> <br>
<br>
　　相对于直接使用sql语句，在应用程序中直接调用存储过程有以下好处： <br>
<br>
　　(1)减少<a class="article" href="http://www.enet.com.cn/networks/" target="_blank">网络</a><a class="article" href="http://www.enet.com.cn/enews/" target="_blank">通信</a>量。调用一个行数不多的存储过程与直接调用sql语句的网络通信量可能不会有很大的差别，可是如果存储过程包含上百行sql语句，那么其性能绝对比一条一条的调用sql语句要高得多。 <br>
<br>
　　(2)执行速度更快。有两个原因：首先，在存储过程创建的时候，数据库已经对其进行了一次解析和优化。其次，存储过程一旦执行，在内存中就会保留一份这个存储过程，这样下次再执行同样的存储过程时，可以从内存中直接调用。 <br>
<br>
　　(3)更强的适应性：由于存储过程对数据库的访问是通过存储过程来进行的，因此数据库开发人员可以在不改动存储过程接口的情况下对数据库进行任何改动，而这些改动不会对应用程序造成影响。 <br>
<br>
　　(4) 布式工作：应用程序和数据库的编码工作可以分别独立进行，而不会相互压制。 <br>
<br>
　　由以上的分析可以看到，在应用程序中使用存储过程是很有必要的。 <br>
<br>
　　<strong>两种不同的存储过程调用方法</strong> <br>
<br>
　　为了突出新方法的优点，首先介绍一下在.net中调用存储过程的&ldquo;官方&rdquo;方法。另外，本文的所有示例程序均工作于sqlserver数据库上，其它情况类似，以后不再一一说明。本文所有例子均采用c#语言。 <br>
<br>
　　要在应用程序中访问数据库，一般性的步骤是：首先声明一个数据库连接sqlconnection，然后声明一个数据库命令sqlcommand，用来执行sql语句和存储过程。有了这两个对象后，就可以根据自己的需要采用不同的执行方式达到目的。需要补充的是，不要忘记在页面上添加如下的引用语句：using system.data.sqlclient。 <br>
<br>
　　就执行存储过程来说，如果执行的是第一类存储过程，那么就要用一个dataadapter将结果填充到一个dataset中，然后就可以使用数据网格控件将结果呈现在页面上了；如果执行的是第二和第三种存储过程，则不需要此过程，只需要根据特定的返回判定操作是否成功完成即可。 <br>
<br>
　　(1)执行一个没有参数的存储过程的代码如下： <br>
<br>
<br>
<br>
sqlconnection conn=new sqlconnection(&ldquo;connectionstring&rdquo;); <br>
sqldataadapter da = new sqldataadapter(); <br>
da.selectcommand = new sqlcommand(); <br>
da.selectcommand.connection = conn; <br>
da.selectcommand.commandtext = &quot;nameofprocedure&quot;; <br>
da.selectcommand.commandtype = commandtype.storedprocedure; <br>
<br>
<br>
　　然后只要选择适当的方式执行此处过程，用于不同的目的即可。 <br>
<br>
　　(2)执行一个有参数的存储过程的代码如下（我们可以将调用存储过程的函数声明为exeprocedure(string inputdate)）： <br>
<br>
<br>
<br>
sqlconnection conn=new sqlconnection(&ldquo;connectionstring&rdquo;); <br>
sqldataadapter da = new sqldataadapter(); <br>
da.selectcommand = new sqlcommand(); <br>
da.selectcommand.connection = conn; <br>
da.selectcommand.commandtext = &quot;nameofprocedure&quot;; <br>
da.selectcommand.commandtype = commandtype.storedprocedure; <br>
（以上代码相同，以下为要添加的代码） <br>
param = new sqlparameter(&quot;@parametername&quot;, sqldbtype.datetime); <br>
param.direction = parameterdirection.input; <br>
param.value = convert.todatetime(inputdate); <br>
da.selectcommand.parameters.add(param); <br>
<br>
<br>
　　这样就添加了一个输入参数。若需要添加输出参数： <br>
<br>
param = new sqlparameter(&quot;@parametername&quot;, sqldbtype.datetime); <br>
param.direction = parameterdirection.output; <br>
param.value = convert.todatetime(inputdate); <br>
da.selectcommand.parameters.add(param); <br>
<br>
　　若要获得参储过程的返回值： <br>
<br>
param = new sqlparameter(&quot;@parametername&quot;, sqldbtype.datetime); <br>
param.direction = parameterdirection.returnvalue; <br>
param.value = convert.todatetime(inputdate); <br>
da.selectcommand.parameters.add(param); <br>
<br>
　　从上面的代码我们可以看出，当存储过程比较多或者存储过程的参数比较多时，这种方法会大大影响开发的速度；另外一方面，如果项目比较大，那么这些用于数据库逻辑的函数在以后的维护中也是一个很大的负担。那么，有没有一种改进的方法可以解决这个问题呢？想到在执行没有参数的存储过程时只需要传入一个存储过程的名字就可以调用相应的存储过程，而且在sqlserver数据库中我们可以直接在查询分析器中敲入&ldquo;存储过程名（参数列表）&rdquo;样的字符串就可以执行存储过程，那么，是否可以把这种思想应用到应用程序中呢？ <br>
<br>
　　于是在编译器中键入相应代码。这些代码是在调用不带参数的存储过程的代码的基础上改的。具体代码如下： <br>
<br>
<br>
<br>
sqlconnection conn=new sqlconnection(&ldquo;connectionstring&rdquo;); <br>
sqldataadapter da = new sqldataadapter(); <br>
da.selectcommand = new sqlcommand(); <br>
da.selectcommand.connection = conn; <br>
da.selectcommand.commandtext = &quot;nameofprocedure（&rsquo;para1&rsquo;,&rsquo;para2&rsquo;,para3）&quot;; <br>
da.selectcommand.commandtype = commandtype.storedprocedure; <br>
<br>
<br>
　　为了使代码更具有代表性，要调用的存储过程的第一个和第二个参数都为字符串类型，第三个参数为整型。执行以后发现，完全可以达到预期的效果！ <br>
<br>
　　<strong>两种调用方法的比较</strong> <br>
　　 <br>
　　通过比较我们可以看到，第二种方法具有一个很明显的优点，那就是可以提高开发速度，节省开发时间，而且代码容易维护，在一定程度上也减少了系统大小。但是，由于对存储过程参数的处理比较笼统，如果要获取输出参数或者得到存储过程的返回值，这种方法就不能满足需要了。虽然如此，但是，这种方法毕竟可以让开发人员少些很大一部分的代码。如果不需要获取输出参数和返回值，那么几乎可以做到&ldquo;一劳永逸&rdquo;。因此在实际的程序开发中，这种方法还是具有一定的实用价值的。 <br> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/miskkk/blog/category/c%23">c#</a>&nbsp;<a href="http://hi.baidu.com/miskkk/blog/item/faa6aa44d53dee44500ffe00.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-08  18:22</pubDate>
        <category><![CDATA[c#]]></category>
        <author><![CDATA[shellshi]]></author>
		<guid>http://hi.baidu.com/miskkk/blog/item/faa6aa44d53dee44500ffe00.html</guid>
</item>

<item>
        <title><![CDATA[C#方法中的ref和out]]></title>
        <link><![CDATA[http://hi.baidu.com/miskkk/blog/item/23f7a8359e1e131991ef3906.html]]></link>
        <description><![CDATA[
		
		<strong>ref&nbsp;&nbsp;&nbsp;&nbsp;<wbr></wbr><br>
&nbsp;&nbsp;&nbsp;&nbsp;  通常我们向方法中传递的是值.方法获得的是这些值的一个拷贝,然后使用这些拷贝,当方法运行完毕后,这些拷贝将被丢弃,而原来的值不将受到影响.此外我们还有其他向方法传递参数的形式,引用(ref)和输出(out).<wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  有时,我们需要改变原来变量中的值,这时,我们可以向方法传递变量的引用,而不是变量的值.引用是一个变量,他可以访问原来变量的值,修改引用将修改原来变量的值.变量的值存储在内存中,可以创建一个引用,他指向变量在内存中的位置.当引用被修改时,修改的是内存中的值,因此变量的值可以将被修改.当我们调用一个含有引用参数的方法时,方法中的参数将指向被传递给方法的相应变量,因此,我们会明白,为什么当修改参数变量的修改也将导致原来变量的值.</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  创建参数按引用传递的方法,需使用关键字ref.例;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  using System;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  class gump</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  {</font><wbr></wbr><br>
<font style="line-height: 1.3em">public double square(ref double x)</font><wbr></wbr><br>
<font style="line-height: 1.3em">{</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;  x=x*x;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;  return x;</font><wbr></wbr><br>
<font style="line-height: 1.3em">}</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  }</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  class TestApp</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  {</font><wbr></wbr><br>
<font style="line-height: 1.3em">public static void Main()</font><wbr></wbr><br>
<font style="line-height: 1.3em">{</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;  gump doit=new gump();</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;  double a=3;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;  double b=0;</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;  Console.WriteLine(&quot;Before square-&gt;a={0},b={1}&quot;,a,b);</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;  b=doit.square(ref a);</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;  Console.WriteLine(&quot;After square-&gt;a={0},b={1}&quot;,a,b);</font><wbr></wbr><br>
<font style="line-height: 1.3em">}</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  }</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  通过测试,我们发现,a的值已经被修改为9了.</font><wbr></wbr><br>
<br>
<wbr></wbr></strong><font style="line-height: 1.3em"><font style="line-height: 1.3em" face="宋体"><wbr></wbr><strong>out</strong></font><wbr></wbr><br>
<strong>&nbsp;&nbsp;&nbsp;&nbsp;  通过指定返回类型,可以从方法返回一个值,有时候(也许还没遇到,但是我们应该有这么个方法),需要返回多个值,虽然我们可以使用ref来完成,但是C#专门提供了一个属性类型,关键字为out.介绍完后,我们将说明ref和out的区别.</strong></font><wbr></wbr><br>
<strong><font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  using System;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  class gump</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  {</font><wbr></wbr><br>
<font style="line-height: 1.3em">public void math_routines(double x,out double half,out double squared,out double cubed)</font><wbr></wbr><br>
<font style="line-height: 1.3em">//可以是:public void math_routines(//ref double x,out double half,out double squared,out double cubed)</font><wbr></wbr><br>
<font style="line-height: 1.3em">//但是,不可以这样:public void math_routines(out double x,out double half,out double squared,out double cubed),对本例来说,因为输出的值要靠x赋值,所以x不能再为输出值</font><wbr></wbr><br>
<font style="line-height: 1.3em">{</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;  half=x/2;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;  squared=x*x;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;  cubed=x*x*x;</font><wbr></wbr><br>
<font style="line-height: 1.3em">}</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  }</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  class TestApp</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  {</font><wbr></wbr><br>
<font style="line-height: 1.3em">public static void Main()</font><wbr></wbr><br>
<font style="line-height: 1.3em">{</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  gump doit=new gump();</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  double x1=600;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  double half1=0;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  double squared1=0;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  double cubed1=0;</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  /*</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  double x1=600;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  double half1;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  double squared1;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  double cubed1;</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  */</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;Before method-&gt;x1={0}&quot;,x1);</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;half1={0}&quot;,half1);</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;squared1={0}&quot;,squared1);</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;cubed1={0}&quot;,cubed1);</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  doit.math_rountines(x1,out half1,out squared1,out cubed1);</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;After method-&gt;x1={0}&quot;,x1);</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;half1={0}&quot;,half1);</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;squared1={0}&quot;,squared1);</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(&quot;cubed1={0}&quot;,cubed1);</font><wbr></wbr><br>
<font style="line-height: 1.3em">}</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  }</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  通过使用out关键字,我们改变了三个变量的值,也就是说out是从方法中传出值.</font><wbr></wbr><br>
<br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  我们发现,ref和out似乎可以实现相同的功能.因为都可以改变传递到方法中的变量的值.但是,二者本质本质的区别就是,ref是传入值,out是传出值.在含有out关键字的方法中,变量必须由方法参数中不含out(可以是ref)的变量赋值或者由全局(即方法可以使用的该方法外部变量)变量赋值,out的宗旨是保证每一个传出变量都必须被赋值.</font><wbr></wbr><br>
<font style="line-height: 1.3em">&nbsp;&nbsp;&nbsp;&nbsp;  上面代码中被/**/注释掉的部分,可以直接使用.也就是说,在调用方法前可以不初始化变量.但是&quot;x1&quot;是要赋值的,否则要报错.而ref参数,在传递给方法时,就已经是还有值的了,所以ref侧重修改.out侧重输出. </font></strong> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/miskkk/blog/category/c%23">c#</a>&nbsp;<a href="http://hi.baidu.com/miskkk/blog/item/23f7a8359e1e131991ef3906.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-08  18:19</pubDate>
        <category><![CDATA[c#]]></category>
        <author><![CDATA[shellshi]]></author>
		<guid>http://hi.baidu.com/miskkk/blog/item/23f7a8359e1e131991ef3906.html</guid>
</item>

<item>
        <title><![CDATA[C#调用外部程序]]></title>
        <link><![CDATA[http://hi.baidu.com/miskkk/blog/item/73a0c8dd9bd364e777c63805.html]]></link>
        <description><![CDATA[
		
		System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();<br>
//设置外部程序名<br>
Info.FileName=&quot;要调用的程序名&quot;;<br>
//设置外部程序的启动参数<br>
Info.Arguments=&quot;&quot;;<br>
//设置外部程序工作目录为D:\Program Files\BitComet<br>
Info.WorkingDirectory=&quot;D:/Program Files/BitComet/&quot;;<br>
//声明一个程序类<br>
System.Diagnostics.ProcessProc;<br>
try<br>
{<br>
//<br>
//启动外部程序<br>
//<br>
Proc=System.Diagnostics.Process.Start(Info);<br>
}<br>
catch<br>
{<br>
&nbsp;&nbsp;  MessageBox.Show(&quot;系统找不到指定的程序文件&quot;,&quot;错误提示！&quot;);<br>
&nbsp;&nbsp;  return;<br>
} 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/miskkk/blog/category/c%23">c#</a>&nbsp;<a href="http://hi.baidu.com/miskkk/blog/item/73a0c8dd9bd364e777c63805.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-08  18:18</pubDate>
        <category><![CDATA[c#]]></category>
        <author><![CDATA[shellshi]]></author>
		<guid>http://hi.baidu.com/miskkk/blog/item/73a0c8dd9bd364e777c63805.html</guid>
</item>

<item>
        <title><![CDATA[C#对INI的操作]]></title>
        <link><![CDATA[http://hi.baidu.com/miskkk/blog/item/166bb42531f0a86835a80f04.html]]></link>
        <description><![CDATA[
		
		<table class="FCK__ShowTableBorders" style="table-layout: fixed">
    <tbody>
        <tr>
            <td>
            <div class="cnt" >INI文件就是扩展名为&ldquo;ini&rdquo;的文件。在Windows系统中，INI文件是很多，最重要的就是&ldquo;System.ini&rdquo;、&ldquo;System32.ini&rdquo;和&ldquo;Win.ini&rdquo;。该文件主要存放用户所做的选择以及系统的各种参数。用户可以通过修改INI文件，来改变应用程序和系统的很多配置。但自从Windows 95的退出，在Windows系统中引入了注册表的概念，INI文件在Windows系统的地位就开始不断下滑，这是因为注册表的独特优点，使应用程序和系统都把许多参数和初始化信息放进了注册表中。但在某些场合，INI文件还拥有其不可替代的地位。本文就来探讨一下C＃是如何对INI进行读写操作。 <br>
            INI文件的结构<br>
            <br>
            INI文件是一种按照特点方式排列的文本文件。每一个INI文件构成都非常类似，由若干段落（section）组成，在每个带括号的标题下面，是若干个以单个单词开头的关键词（keyword）和一个等号，等号右边的就是关键字对应的值（value）。其一般形式如下： <br>
            <br>
            [Section1]<br>
            　　KeyWord1 = Valuel<br>
            　　KeyWord2 = Value2<br>
            　　　……<br>
            　　[Section2]<br>
            　　KeyWord3 = Value3<br>
            　　KeyWord4 = Value4 <br>
            <br>
            本文中介绍的程序设计及运行环境： <br>
            ● 微软视窗2000 高级服务器版 <br>
            ● .Net Framework SDK正式版 <br>
            C＃和Win32 API函数<br>
            <br>
            C＃并不像C＋＋，拥有属于自己的类库。C＃使用的类库是.Net框架为所有.Net程序开发提供的一个共有的类库&mdash;&mdash;.Net FrameWork SDK。虽然.Net FrameWork SDK内容十分庞大，功能也非常强大，但还不能面面俱到，至少它并没有提供直接操作INI文件所需要的相关的类。在本文中，C＃操作INI文件使用的是Windows系统自带Win32的API函数&mdash;&mdash;WritePrivateProfileString（）和GetPrivateProfileString（）函数。这二个函数都位于&ldquo;kernel32.dll&rdquo;文件中。 <br>
            我们知道在C＃中使用的类库都是托管代码（Managed Code）文件，而Win32的API函数所处的文件，都是非托管代码（Unmanaged Code）文件。这就导致了在C＃中不可能直接使用这些非托管代码文件中的函数。好在.Net框架为了保持对下的兼容，也为了充分利用以前的资源，提出了互操作，通过互操作可以实现对Win32的API函数的调用。互操作不仅适用于Win32的API函数，还可以用来访问托管的COM对象。C＃中对Win32的API函数的互操作是通过命名空间&ldquo;System.Runtime.InteropServices&rdquo;中的&ldquo;DllImport&rdquo;特征类来实现的。它的主要作用是指示此属性化方法是作为非托管DLL的输出实现的。下面代码就是在C＃利用命名空间&ldquo;System.Runtime.InteropServices&rdquo;中的&ldquo;DllImport&rdquo;特征类申明上面二个Win32的API函数： <br>
            C＃申明INI文件的写操作函数WritePrivateProfileString（）：<br>
            <br>
            [ DllImport ( &quot;kernel32&quot; ) ]<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  private static extern long WritePrivateProfileString ( string <br>
            section ,<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  string key , string val , string filePath ) ; <br>
            <br>
            参数说明：section：INI文件中的段落；key：INI文件中的关键字；val：INI文件中关键字的数值；filePath：INI文件的完整的路径和名称。 <br>
            C＃申明INI文件的读操作函数GetPrivateProfileString（）：<br>
            <br>
            [ DllImport ( &quot;kernel32&quot; ) ]<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  private static extern int GetPrivateProfileString ( string section ,<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  string key , string def , StringBuilder retVal ,<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  int size , string filePath ) ; <br>
            <br>
            参数说明：section：INI文件中的段落名称；key：INI文件中的关键字；def：无法读取时候时候的缺省数值；retVal：读取数值；size：数值的大小；filePath：INI文件的完整路径和名称。 <br>
            <br>
            C＃中读写INI文件的关键步骤和解决方法<br>
            C＃对INI文件进行写操作：<br>
            对INI文件进行写操作，是通过组件button2的&quot;Click&quot;事件来实现的。这里有一点应该注意，当在调用WritePrivateProfileString（）对INI文件进行写操作的时候，如果此时在INI文件中存在和要写入的信息相同的段落名称和关键字，则将覆盖此INI信息。下面是button2组件的&quot;Click&quot;事件对应的代码清单： <br>
            <br>
            private void button2_Click ( object sender , System.EventArgs e ) <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  string FileName = textBox1.Text ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  string section = textBox2.Text ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  string key = textBox3.Text ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  string keyValue = textBox4.Text ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  WritePrivateProfileString ( section , key , keyValue , FileName ) ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  MessageBox.Show ( &quot;成功写入INI文件！&quot; , &quot;信息&quot; ) ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  } <br>
            <br>
            C＃对INI文件进行读操作：<br>
            正确读取INI的必须满足三个前提：INI文件的全路径、段落名称和关键字名称。否则就无法正确读取。你可以设定读取不成功后的缺省数值，在下面的程序中，为了直观设定的是&ldquo;无法读取对应数值！&rdquo;字符串，读取INI文件是通过button3组件的&ldquo;Click&rdquo;事件来实现的，下面是其对应的代码清单： <br>
            <br>
            private void button3_Click ( object sender , System.EventArgs e ) <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  {<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  StringBuilder temp = new StringBuilder ( 255 ) ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  string FileName = textBox1.Text ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  string section = textBox2.Text ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  string key = textBox3.Text ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  int i = GetPrivateProfileString ( section , key ,&quot;无法读取对应数值！&quot;,<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  temp , 255 , FileName ) ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;  textBox4.Text = temp.ToString ( ) ;<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }</div>
            </td>
        </tr>
    </tbody>
</table> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/miskkk/blog/category/c%23">c#</a>&nbsp;<a href="http://hi.baidu.com/miskkk/blog/item/166bb42531f0a86835a80f04.html#comment">查看评论</a>]]></description>
        <pubDate>2009-06-08  18:16</pubDate>
        <category><![CDATA[c#]]></category>
        <author><![CDATA[shellshi]]></author>
		<guid>http://hi.baidu.com/miskkk/blog/item/166bb42531f0a86835a80f04.html</guid>
</item>


</channel>
</rss>