C#如何按行读取记事本内的值

来源:百度知道 编辑:UC知道 时间:2024/05/13 11:19:42
若记事本内容为:
123
456
789
如何按行读取~~~第一次读出123第二次读出456第三次读出789
若不能实现按行读取~~那么直接读取记事本内的值也可以.比如说一次性全都读出来123456789,
读出来放到一个string里面.

System.IO.StreamReader sr = new System.IO.StreamReader("C:\\1.txt");
textBox1.Text = sr.ReadToEnd();

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new StreamReader(ofd.FileName);
textBox1.Text = sr.ReadToEnd();
sr.Close();
}
}

菜鸟