#region Using directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
#endregion
namespace UsingStatement
{
partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void openFile_Click(object sender, System.EventArgs e)
{
openFileDialog.ShowDialog();
}
private void openFileDialog_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
string fullPathname = openFileDialog.FileName;
FileInfo src = new FileInfo(fullPathname);
filename.Text = src.Name;
source.Text = "";
TextReader reader = new StreamReader(fullPathname);
/* 如果用using 语句的话
using(TextReader reader = new StreamReader(fullPathname); )
{
string line;
while ((line = reader.ReadLine()) != null)
{
source.Text += line + "/n";
}
不用close了 创建的对象在using 语句结束后被摧毁了
}
}
}
}
}