openFileDialog1.ShowDialog();
openFileDialog1.Filter = "文本文件|*.txt|所有文件|*.*";
string PathFile = openFileDialog1.FileName;
string[] StrLine = File.ReadAllLines(PathFile);
for (int i = 0; i < StrLine.Length; i++)
{
richTextBox1.Text = StrLine[i].ToString() + "\r\n";
}
openFileDialog1.Filter = "文本文件|*.txt|所有文件|*.*";
string PathFile = openFileDialog1.FileName;
string[] StrLine = File.ReadAllLines(PathFile);
for (int i = 0; i < StrLine.Length; i++)
{
richTextBox1.Text = StrLine[i].ToString() + "\r\n";
}
openFileDialog1.Filter = "文本文件|*.txt|所有文件|*.*";
string PathFile = openFileDialog1.FileName;
string[] StrLine = File.ReadAllLines(PathFile);
StringBuilder sb = new StringBuilder();foreach( string str in StrLine)
{
sb.Append(str).Append("\r\n");
}richTextBox1.Text = sb.ToString();频繁的字符串操作不要直接用string去拼接,用stringbuilder!!!
openFileDialog1.Filter = "文本文件|*.txt|所有文件|*.*";
string PathFile = openFileDialog1.FileName;
string[] StrLine = File.ReadAllLines(PathFile);
StringBuilder str= new StringBuilder();foreach( string str in StrLine)
{
str.Append(str).Append("\r\n");
}richTextBox1.Text = str.ToString();
这个要看拼接的次数,次数不多的话,效率反而比stringbuilder要高