语句中的一些变量的定义,就略去了
1.
try
{
sr = new StreamReader(temp, System.Text.Encoding.Default);
strHtmlModule = sr.ReadToEnd(); // read the file
}
catch
{
Console.WriteLine("HTML Module file not be found");
return null;
}
finally
{
if (null != sr)
{
sr.Close();
}
}
2.
using (sr = new StreamReader(temp, System.Text.Encoding.Default))
{
try
{
strHtmlModule = sr.ReadToEnd(); // read the file
}
catch
{
Console.WriteLine("HTML Module file not be found");
return null;
}
}
Note:
第一种方式是我们通常用的方式,他是针对于托管代码的,这个就不多说了。
第二种方式是针对于非托管代码的,放在using 里的语句,开辟的资源,会在其代码块被走完之后被自动释放掉,因为这个using 是特意为这个设计的。
posted on 2008-05-18 20:32
WenLe 阅读(396)
评论(0) 编辑 收藏