在C#中? [英] \n in C#?

查看:57
本文介绍了在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


大概是你们大部分学习的第一件事,但我不知道用于C#的

换行符。


谢谢,

詹姆斯

解决方案

你可以使用"换行符" 环境的属性class ...
http://msdn.microsoft.com/library/de...wlinetopic.asp


-

Tim Wilson

.. NET Compact Framework MVP


" James" < JA ********** @ gmail.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...

大家好,

大多数人都可以学习第一件事,但我不知道C#的换行符。

谢谢,
James



string newline = System.Environment.NewLine;


那是'你如何为你运行的任何系统检索它。

请记住,你的.net代码有时可以在linux系统上运行(或任何unix

)单声道。如果你想打印一行没有新行

之后,请使用:


Console.Write(" blahblah");


如果你想在屏幕上打印一行换行符

(独立于系统)使用:


控制台。 WriteLine(" bbllaahh);


这将跨平台工作,以及上面的第一行代码。

不要硬编码特定换行序列,例如\ n,\\\\ n或\。


-

jeremiah();


詹姆斯写道:

大家好,

大概你们大部分学习的第一件事,但我不知道
C#的换行符。

谢谢,
James



jeremiah johnson< us ** @ example .COM>写道:


< snip>

这将跨平台工作,以及上面的第一行代码。
不要在特定的换行序列中进行硬编码,例如\ n,\\\\ n或\r。




这取决于你的''干嘛如果您正在写入需要系统换行符的文件,那么您确实应该使用WriteLine和/或

Environment.NewLine。

但是,如果您正在处理网络协议,那么您绝对应该使用\ r,\ n或\\\\ n来支付
*,因为协议将(或至少
)定义*它认为是换行符。那时,如果

你使用Environment.NewLine,你*将*在一个平台上有一个错误或

其他。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复群组,请不要给我发邮件


Hi all,

Probably the first thing most of you learn, but I don''t know the
newline character for C#.

Thanks,
James

解决方案

You can use the "NewLine" property of the "Environment" class...
http://msdn.microsoft.com/library/de...wlinetopic.asp

--
Tim Wilson
..NET Compact Framework MVP

"James" <ja**********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...

Hi all,

Probably the first thing most of you learn, but I don''t know the
newline character for C#.

Thanks,
James



string newline = System.Environment.NewLine;

That''s how you retrieve it for whatever system you''re running on.
Remember, your .net code can sometimes run on linux systems (or any unix
at all) using Mono. If you want to print a line without a newline
after, use:

Console.Write("blahblah");

If you want to print a line to the screen FOLLOWED by a newline
(independent of the system) use:

Console.WriteLine("bbllaahh");

This will work cross platform, as well as the first line of code above.
Don''t hardcode in specific newline sequences such as \n, \r\n, or \r.

--
jeremiah();

James wrote:

Hi all,

Probably the first thing most of you learn, but I don''t know the
newline character for C#.

Thanks,
James



jeremiah johnson <us**@example.com> wrote:

<snip>

This will work cross platform, as well as the first line of code above.
Don''t hardcode in specific newline sequences such as \n, \r\n, or \r.



It depends on what you''re doing. If you''re writing to files which want
the system newline, then you should indeed use WriteLine and/or
Environment.NewLine.

If, however, you''re dealing with a network protocol, you absolutely
*should* use \r, \n or \r\n, because the protocol will (or at least
should) define what *it* thinks is the the newline. At that point, if
you use Environment.NewLine you *will* have a bug on one platform or
other.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


这篇关于在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆