3 回答

TA貢獻1772條經(jīng)驗 獲得超5個贊
取決于平臺。在Windows上,它實際上是“ \ r \ n”。
從MSDN:
對于非Unix平臺,包含“ \ r \ n”的字符串,對于Unix平臺,包含“ \ n”的字符串。

TA貢獻1818條經(jīng)驗 獲得超3個贊
Environment.NewLine從源代碼的確切實現(xiàn):
.NET 4.6.1中的實現(xiàn):
/*===================================NewLine====================================
**Action: A property which returns the appropriate newline string for the given
** platform.
**Returns: \r\n on Win32.
**Arguments: None.
**Exceptions: None.
==============================================================================*/
public static String NewLine {
get {
Contract.Ensures(Contract.Result<String>() != null);
return "\r\n";
}
}
資源
.NET Core中的實現(xiàn):
/*===================================NewLine====================================
**Action: A property which returns the appropriate newline string for the
** given platform.
**Returns: \r\n on Win32.
**Arguments: None.
**Exceptions: None.
==============================================================================*/
public static String NewLine {
get {
Contract.Ensures(Contract.Result() != null);
#if !PLATFORM_UNIX
return "\r\n";
#else
return "\n";
#endif // !PLATFORM_UNIX
}
}
來源(在中System.Private.CoreLib)
public static string NewLine => "\r\n";
來源(在中System.Runtime.Extensions)

TA貢獻1784條經(jīng)驗 獲得超8個贊
如其他人所述,Environment.NewLine返回平臺特定的字符串以開始新行,該字符串應(yīng)為:
"\r\n" (\ u000D \ u000A)對于Windows
"\n" (\ u000A)對于Unix
"\r" (\ u000D)對于Mac(如果存在這種實現(xiàn))
請注意,在寫入控制臺時,并非嚴(yán)格要求Environment.NewLine。"\n"如果需要,控制臺流將轉(zhuǎn)換為適當(dāng)?shù)膿Q行序列。
- 3 回答
- 0 關(guān)注
- 1947 瀏覽
添加回答
舉報