IOComponent.csusing 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.csusing 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 执行释放资源的操作有什么区别吗
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.csusing 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 执行释放资源的操作有什么区别吗
解决方案 »
- 变量初始化问题
- 正在学习C#,菜鸟请教多线程的问题?
- 关于C# 2003 application应用中的datagrid中追加checkbox列
- C# 动态调用 Java webservice
- 如何在C#中定义包含数组成员的struct
- remoting中远程对象的定义问题!~!!
- 类的成员什么时候定义为静态,什么时候定义为普通的,都定义为静态不行吗?
- 关于Average()与lambda 表达式
- PictureBox如何显示出边框?
- double转字符串?
- 请问如何把vs.net2003自带的水晶报表,Version=9.1.5000.0,如何部署到web 服务器呢?
- 关于WebForm中异步程序的问题。
我得理解是Dispose释放的是里面指定的对象,~IOComponent() 释放该类自己。
这里的pDis==true 和 pDis==false 执行完了都会释放资源,应该没什么