C# 当我使用StringBuilder.Append而不是.AppendLine时,是否需要添加其他.Append(crlf)文件?
我正在修改我在这里找到的一些代码:,但在VS 2003/.NET 1.1中,无法识别StringBuilder的AppendLine方法,因此我将其截断为.Append 我现在是否需要在每次调用Append之后添加#13#10左右-我假设AppendLine会自动执行这些操作。是的C# 当我使用StringBuilder.Append而不是.AppendLine时,是否需要添加其他.Append(crlf)文件?,c#,.net,visual-studio,append,stringbuilder,C#,.net,Visual Studio,Append,Stringbuilder,我正在修改我在这里找到的一些代码:,但在VS 2003/.NET 1.1中,无法识别StringBuilder的AppendLine方法,因此我将其截断为.Append 我现在是否需要在每次调用Append之后添加#13#10左右-我假设AppendLine会自动执行这些操作。是的 AppendLine()将附加其参数,后跟Environment.Newline 如果不调用AppendLine(),则需要自己包含新行。是。不过,要小心将其视为CRLF,因此值得您自己使用Environment.N
AppendLine()
将附加其参数,后跟Environment.Newline
如果不调用
AppendLine()
,则需要自己包含新行。是。不过,要小心将其视为CRLF,因此值得您自己使用Environment.NewLine以实现交叉兼容性
[System.Runtime.InteropServices.ComVisible(false)]
public StringBuilder AppendLine() {
Contract.Ensures(Contract.Result<stringbuilder>() != null);
return Append(Environment.NewLine);
}
[System.Runtime.InteropServices.ComVisible(false)]
public StringBuilder AppendLine(string value) {
Contract.Ensures(Contract.Result<stringbuilder>() != null);
Append(value);
return Append(Environment.NewLine);
}
[System.Runtime.InteropServices.ComVisible(false)]
公共StringBuilder AppendLine(){
Contract.sure(Contract.Result()!=null);
返回Append(Environment.NewLine);
}
[System.Runtime.InteropServices.ComVisible(false)]
公共StringBuilder追加行(字符串值){
Contract.sure(Contract.Result()!=null);
附加(值);
返回Append(Environment.NewLine);
}
编辑:除非您因为硬件原因而特别需要使用CRLF,否则我猜。反编译了
StringBuilder.AppendLine的源代码
/// <summary>
/// Appends the default line terminator to the end of the current <see cref="T:System.Text.StringBuilder"/> object.
///
/// </summary>
///
/// <returns>
/// A reference to this instance after the append operation has completed.
///
/// </returns>
/// <exception cref="T:System.ArgumentOutOfRangeException">Enlarging the value of this instance would exceed <see cref="P:System.Text.StringBuilder.MaxCapacity"/>.
/// </exception><filterpriority>1</filterpriority>
[ComVisible(false)]
[__DynamicallyInvokable]
public StringBuilder AppendLine()
{
return this.Append(Environment.NewLine);
}
//
///将默认行终止符追加到当前对象的末尾。
///
///
///
///
///追加操作完成后对此实例的引用。
///
///
///扩大此实例的值将超过。
/// 1
[ComVisible(false)]
[[uuuu动态调用可禁用]
公共StringBuilder AppendLine()
{
返回this.Append(Environment.NewLine);
}
是的(多一些字符,我可以发表评论),您可以使用环境。Newline我想知道“\r\n”对这个项目(CE/CF)是否比环境更安全。Newline(我通常更喜欢)。它是否附加了\r\n
它是否使用了环境。Newline
?@ClayShannon:您是对的;我应该说,Environment.NewLine
.Environment.NewLine在.NET 1.1感谢您发布这个@Dustin Kingen!