CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

求助 在vs2003中构建dll文件和析构函数应用问题

楼主lgq_12345(lgq)2006-03-02 08:50:21 在 .NET技术 / C# 提问

IOComponent.cs  
   
  using   System;  
  using   System.Text;  
  using   System.IO;  
  using   System.ComponentModel;  
   
  namespace   ClassLibrary2  
  {  
  ///   <summary>  
  ///   Class1   的摘要说明。  
  ///   </summary>  
  public   class   IOComponent:Component  
  {  
  StreamReader   myStreamReader;  
  public   void   DoRead()  
  {  
  string   strReadFile;  
  Console.WriteLine("请输入欲读取的文件名称");  
  strReadFile=Console.ReadLine();  
  myStreamReader=new   StreamReader(strReadFile);  
  Console.WriteLine("开始读取文件");  
          ReadText();  
  }  
  private   void   ReadText()  
  {  
  string   strBufferText;  
  do  
  {    
                                                      strBufferText=myStreamReader.ReadLine();  
      Console.WriteLine(strBufferText);  
  }while(strBufferText!=null);  
  }  
  protected   override   void   Dispose(bool   pDis)  
  {  
  if(pDis==true)  
  {  
  Console.WriteLine("此时传入的参数为true");  
  Console.WriteLine("关闭数据流对象");  
  myStreamReader.Close();  
  }  
  else  
  {  
  Console.WriteLine("此时传入的参数为false");  
  Console.WriteLine("清楚未受管理的代码");  
  }  
  base.Dispose   (pDis);  
  }  
  ~IOComponent()  
  {  
  Console.WriteLine("析构函数被调用");  
  Console.WriteLine("调用Dispose(false)");  
                  Dispose(false);  
  Console.ReadLine();  
  }  
  public   IOComponent()  
  {  
  //  
  //   TODO:   在此处添加构造函数逻辑  
  //  
  }  
  }  
  }  
   
   
  UsingIOComponent.cs  
   
  using   System;    
  class   UsingIOComponent    
  {  
  public   static   void   Main(string[]   args)    
  {  
                      IOComponent   myIOComponent=new   IOComponent();  
      myIOComponent.DoRead();  
        myIOComponent.Dispose();  
  Console.ReadLine();  
  }  
  }  
   
  我的问题如下  
   
    1:如何把IOComponent.cs文件编译成为dll文件   被UsingIOComponent.cs引用   在vs2003应该如何作?  
     
    2: protected   override   void   Dispose(bool   pDis)  
  {  
  if(pDis==true)  
  {  
  Console.WriteLine("此时传入的参数为true");  
  Console.WriteLine("关闭数据流对象");  
  myStreamReader.Close();  
  }  
  else  
  {  
  Console.WriteLine("此时传入的参数为false");  
  Console.WriteLine("清楚未受管理的代码");  
  }  
  base.Dispose   (pDis);  
  }  
  ~IOComponent()  
  {  
  Console.WriteLine("析构函数被调用");  
  Console.WriteLine("调用Dispose(false)");  
                  Dispose(false);  
  Console.ReadLine();  
  }  
         
                    既然     Dispose方法可以   释放资源   为什么还要用   ~IOComponent()   这个类的析构函数?  
  3:pDis==true   和   pDis==false   执行释放资源的操作有什么区别吗 问题点数:10、回复次数:1Top

1 楼litp(天道酬勤)回复于 2006-03-02 17:20:00 得分 0

新建一个类库项目,把文件添加进去编译一下就是dll了。  
  我得理解是Dispose释放的是里面指定的对象,~IOComponent()   释放该类自己。  
  这里的pDis==true   和   pDis==false   执行完了都会释放资源,应该没什么  
  Top

相关问题

  • dll函数
  • DLL导出函数
  • dll函数问题
  • 关于*.dll函数
  • 转换dll函数
  • DLL调用函数问题
  • .dll中函数的定义?
  • DLL的函数调用????
  • 关于DLL的初始化函数和退出函数
  • 如何查看DLL内的函数?

关键词

  • 函数
  • 文件
  • pdis
  • iocomponent
  • 析构函数
  • mystreamreader
  • strbuffertext
  • console
  • strreadfile
  • writeline

得分解答快速导航

  • 帖主:lgq_12345

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo