StreamReader.EndOfStream
using和 string != null
in 文件处理 有什么区别
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
while (!reader.EndOfStream)
{
data = BreakLine(line);
DataRow dr = _DataTable.NewRow();
// protect against overflow
int maxColumns = Math.Min(_DataTable.Columns.Count, data.Length);
for (int i = 0; i < maxColumns; i++)
{
dr[i] = data[i];
}
_DataTable.Rows.Add(dr);
line = reader.ReadLine();
}