\r\n的问题

lingjin520 2012-07-16 09:36:10
private void buttonOK_Click(object sender, EventArgs e)
{
string output;
output = "Name: " + this.textBoxName.Text + "\r\n";
output += "Address: " + this.textBoxAddress.Text + "\r\n";
output += "Occupation: " + this.textBoxOccupation.Text + "\r\n";
output += "Age: " + this.textBoxAge.Text + "\r\n";

this.textBoxOutput.Text = output;

}


输出是:
Name: Tracy
Address: cn
Occupation: IT
Age: 25

为什么要用\r\n,而不是\n或只是\r呢?
...全文
169 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Change_L 2012-07-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

但考虑到跨平台,更好的习惯是用Environment.NewLine属性。
[/Quote]

++
EnForGrass 2012-07-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

但考虑到跨平台,更好的习惯是用Environment.NewLine属性。
[/Quote]
我一般用这个
lingjin520 2012-07-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

回车=将光标移到行的开始处,\r
换行=将光标移到下一行,\n
回车换行=将光标移到下一行的开始处,\r\n
[/Quote]
如果我写成output = "Name: " + this.textBoxName.Text + "\n";
这样子为什么并不能达到换行显示的效果呢?
q107770540 2012-07-16
  • 打赏
  • 举报
回复
但考虑到跨平台,更好的习惯是用Environment.NewLine属性。
q107770540 2012-07-16
  • 打赏
  • 举报
回复
回车=将光标移到行的开始处,\r
换行=将光标移到下一行,\n
回车换行=将光标移到下一行的开始处,\r\n

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧