TextWriter.WriteLine TextWriter.WriteLine TextWriter.WriteLine TextWriter.WriteLine Method

定義

將資料寫入文字資料流,後接行結束字元。Writes data to the text stream, followed by a line terminator.

多載

WriteLine(String, Object, Object) WriteLine(String, Object, Object) WriteLine(String, Object, Object) WriteLine(String, Object, Object)

使用與 Format(String, Object, Object) 方法相同的語意,將格式化字串和新行寫入文字資料流。Writes a formatted string and a new line to the text stream, using the same semantics as the Format(String, Object, Object) method.

WriteLine(Char[], Int32, Int32) WriteLine(Char[], Int32, Int32) WriteLine(Char[], Int32, Int32) WriteLine(Char[], Int32, Int32)

將字元的子陣列寫入文字資料流,後接行結束字元。Writes a subarray of characters to the text stream, followed by a line terminator.

WriteLine(String, Object[]) WriteLine(String, Object[]) WriteLine(String, Object[]) WriteLine(String, Object[])

使用與 Format(String, Object) 相同的語意,寫出文字資料流中的格式化字串和新行。Writes out a formatted string and a new line to the text stream, using the same semantics as Format(String, Object).

WriteLine(String, Object) WriteLine(String, Object) WriteLine(String, Object) WriteLine(String, Object)

使用與 Format(String, Object) 方法相同的語意,將格式化字串和新行寫入文字資料流。Writes a formatted string and a new line to the text stream, using the same semantics as the Format(String, Object) method.

WriteLine(UInt64) WriteLine(UInt64) WriteLine(UInt64) WriteLine(UInt64)

將 8 位元組不帶正負號的整數文字表示寫入文字資料流,後接行結束字元。Writes the text representation of an 8-byte unsigned integer to the text stream, followed by a line terminator.

WriteLine(UInt32) WriteLine(UInt32) WriteLine(UInt32) WriteLine(UInt32)

將 4 位元組不帶正負號的整數文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator.

WriteLine(String, Object, Object, Object) WriteLine(String, Object, Object, Object) WriteLine(String, Object, Object, Object) WriteLine(String, Object, Object, Object)

使用與 Format(String, Object) 相同的語意,寫出文字資料流中的格式化字串和新行。Writes out a formatted string and a new line to the text stream, using the same semantics as Format(String, Object).

WriteLine(StringBuilder) WriteLine(StringBuilder) WriteLine(StringBuilder) WriteLine(StringBuilder)

將字串產生器的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a string builder to the text stream, followed by a line terminator.

WriteLine(String) WriteLine(String) WriteLine(String) WriteLine(String)

將字串寫入文字資料流,後接行結束字元。Writes a string to the text stream, followed by a line terminator.

WriteLine(Single) WriteLine(Single) WriteLine(Single) WriteLine(Single)

將 4 位元組浮點數值的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a 4-byte floating-point value to the text stream, followed by a line terminator.

WriteLine(Double) WriteLine(Double) WriteLine(Double) WriteLine(Double)

將 8 位元組浮點數值的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a 8-byte floating-point value to the text stream, followed by a line terminator.

WriteLine(Object) WriteLine(Object) WriteLine(Object) WriteLine(Object)

藉由呼叫該物件上的 ToString 方法,後接行結束字元,將物件的文字表示寫入文字資料流。Writes the text representation of an object to the text stream, by calling the ToString method on that object, followed by a line terminator.

WriteLine(Int64) WriteLine(Int64) WriteLine(Int64) WriteLine(Int64)

將 8 位元組帶正負號的整數文字表示寫入文字資料流,後接行結束字元。Writes the text representation of an 8-byte signed integer to the text stream, followed by a line terminator.

WriteLine(Int32) WriteLine(Int32) WriteLine(Int32) WriteLine(Int32)

將 4 位元組帶正負號的整數文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator.

WriteLine(Decimal) WriteLine(Decimal) WriteLine(Decimal) WriteLine(Decimal)

將十進位值的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a decimal value to the text stream, followed by a line terminator.

WriteLine(Char[]) WriteLine(Char[]) WriteLine(Char[]) WriteLine(Char[])

將字元的陣列寫入文字資料流,後接行結束字元。Writes an array of characters to the text stream, followed by a line terminator.

WriteLine(Char) WriteLine(Char) WriteLine(Char) WriteLine(Char)

將字元寫入文字資料流,後接行結束字元。Writes a character to the text stream, followed by a line terminator.

WriteLine(Boolean) WriteLine(Boolean) WriteLine(Boolean) WriteLine(Boolean)

Boolean 值的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a Boolean value to the text stream, followed by a line terminator.

WriteLine() WriteLine() WriteLine() WriteLine()

將行結束字元寫入文字資料流。Writes a line terminator to the text stream.

WriteLine(ReadOnlySpan<Char>) WriteLine(ReadOnlySpan<Char>) WriteLine(ReadOnlySpan<Char>) WriteLine(ReadOnlySpan<Char>)

將字元範圍的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a character span to the text stream, followed by a line terminator.

WriteLine(String, Object, Object) WriteLine(String, Object, Object) WriteLine(String, Object, Object) WriteLine(String, Object, Object)

使用與 Format(String, Object, Object) 方法相同的語意,將格式化字串和新行寫入文字資料流。Writes a formatted string and a new line to the text stream, using the same semantics as the Format(String, Object, Object) method.

public:
 virtual void WriteLine(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1);
public virtual void WriteLine (string format, object arg0, object arg1);
abstract member WriteLine : string * obj * obj -> unit
override this.WriteLine : string * obj * obj -> unit
Public Overridable Sub WriteLine (format As String, arg0 As Object, arg1 As Object)

參數

format
String String String String

複合格式字串。A composite format string.

arg0
Object Object Object Object

第一個要格式化和寫入的物件。The first object to format and write.

arg1
Object Object Object Object

第二個要格式化和寫入的物件。The second object to format and write.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

format 不是有效的複合格式字串。format is not a valid composite format string.

-或--or- 格式項目的索引小於 0 (零),或大於或等於要格式化的物件數目 (就這個方法多載而言,是兩個)。The index of a format item is less than 0 (zero), or greater than or equal to the number of objects to be formatted (which, for this method overload, is two).

備註

這個方法會使用複合格式,將物件的值轉換成其字串表示,並在字串中內嵌該標記法。This method uses composite formatting to convert the value of an object to its string representation and to embed that representation in a string. .NET 提供廣泛的格式化支援,在下列格式設定主題中有更詳細的說明:.NET provides extensive formatting support, which is described in greater detail in the following formatting topics:

format參數包含零個或多個與零或多個索引預留位置(稱為格式專案)混合的文字,其對應于此方法之參數清單中的物件。The format parameter consists of zero or more runs of text intermixed with zero or more indexed placeholders, called format items, that correspond to an object in the parameter list of this method. 格式化程式會將每個格式專案取代為對應物件值的字串表示。The formatting process replaces each format item with the string representation of the value of the corresponding object.

格式專案的語法如下:The syntax of a format item is as follows:

{index[,length] [:格式字串]}{index[,length][:formatString]}

在方括號中的元素是選擇性的元素。Elements in square brackets are optional. 下表說明每個元素。The following table describes each element. 如需複合格式功能的詳細資訊,包括格式專案的語法,請參閱複合格式For more information about the composite formatting feature, including the syntax of a format item, see Composite Formatting.

元素Element 說明Description
索引index 要格式化之物件的參數清單中以零為起始的位置。The zero-based position in the parameter list of the object to be formatted. 如果index所指定的物件是null,則會將格式String.Empty專案取代為。If the object specified by index is null, the format item is replaced by String.Empty. 因為此多載在其參數清單中有兩個物件,所以index的值必須一律為0或1。Because this overload has two objects in its parameter list, the value of index must always be 0 or 1. 如果索引位置中沒有參數, FormatException則會擲回。If there is no parameter in the index position, a FormatException is thrown.
length,length 參數的字串表示中的最小字元數。The minimum number of characters in the string representation of the parameter. 如果是正數,則參數會靠右對齊;如果是負數,則會靠左對齊。If positive, the parameter is right-aligned; if negative, it is left-aligned.
:formatString:formatString 要格式化之物件所支援的標準或自訂格式字串。A standard or custom format string that is supported by the object to be formatted. 格式字串的可能值與物件的ToString(string format)方法所支援的值相同。Possible values for formatString are the same as the values supported by the object's ToString(string format) method. 如果未指定格式字串,且要IFormattable格式化的物件會執行介面, null format會傳遞做為做為IFormattable.ToString格式字串之參數的值。If formatString is not specified and the object to be formatted implements the IFormattable interface, null is passed as the value of the format parameter that is used as the IFormattable.ToString format string.

開頭和尾端的大括弧字元("{" 和 "}")是必要的。The leading and trailing brace characters, "{" and "}", are required. 若要在中format指定單一常值大括弧字元,請指定兩個開頭或尾端的大括弧字元,也就是 "{{" 或 "}}"。To specify a single literal brace character in format, specify two leading or trailing brace characters; that is, "{{" or "}}".

這個方法不會在指定的字串中搜尋個別的新行字元 (十六進位的 0x000a),也不會以 NewLine 取代它們。This method does not search the specified string for individual newline characters (hexadecimal 0x000a) and replace them with NewLine.

如果格式字串中未參考指定的物件,則會忽略它。If a specified object is not referenced in the format string, it is ignored.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(Char[], Int32, Int32) WriteLine(Char[], Int32, Int32) WriteLine(Char[], Int32, Int32) WriteLine(Char[], Int32, Int32)

將字元的子陣列寫入文字資料流,後接行結束字元。Writes a subarray of characters to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(cli::array <char> ^ buffer, int index, int count);
public virtual void WriteLine (char[] buffer, int index, int count);
abstract member WriteLine : char[] * int * int -> unit
override this.WriteLine : char[] * int * int -> unit
Public Overridable Sub WriteLine (buffer As Char(), index As Integer, count As Integer)

參數

buffer
Char[]

資料讀取來源的字元陣列。The character array from which data is read.

index
Int32 Int32 Int32 Int32

buffer 中開始讀取資料的字元位置。The character position in buffer at which to start reading data.

count
Int32 Int32 Int32 Int32

要寫入的最大字元數。The maximum number of characters to write.

例外狀況

緩衝區長度減去 index 會小於 countThe buffer length minus index is less than count.

buffer 參數為 nullThe buffer parameter is null.

發生 I/O 錯誤。An I/O error occurs.

備註

這個方法會從count開始于位置index的字元TextWriter陣列, buffer將資料中的字元寫入其中。This method will write count characters of data into this TextWriter from the buffer character array starting at position index.

這個多載相當於呼叫Write(Char[])方法, WriteLine後面接著針對和( + count indexbuffer之間index的每個字元。This overload is equivalent to calling the Write(Char[]) method followed by WriteLine for each character in buffer between index and (index + count).

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(String, Object[]) WriteLine(String, Object[]) WriteLine(String, Object[]) WriteLine(String, Object[])

使用與 Format(String, Object) 相同的語意,寫出文字資料流中的格式化字串和新行。Writes out a formatted string and a new line to the text stream, using the same semantics as Format(String, Object).

public:
 virtual void WriteLine(System::String ^ format, ... cli::array <System::Object ^> ^ arg);
public virtual void WriteLine (string format, params object[] arg);
abstract member WriteLine : string * obj[] -> unit
override this.WriteLine : string * obj[] -> unit
Public Overridable Sub WriteLine (format As String, ParamArray arg As Object())

參數

format
String String String String

複合格式字串。A composite format string.

arg
Object[]

物件陣列,包含零或多個要格式化和寫入的物件。An object array that contains zero or more objects to format and write.

例外狀況

傳入的字串或物件為 nullA string or object is passed in as null.

發生 I/O 錯誤。An I/O error occurs.

format 不是有效的複合格式字串。format is not a valid composite format string.

-或--or- 格式項目的索引小於 0 (零),或大於或等於 arg 陣列的長度。The index of a format item is less than 0 (zero), or greater than or equal to the length of the arg array.

備註

這個方法會使用複合格式,將物件的值轉換成其字串表示,並在字串中內嵌該標記法。This method uses composite formatting to convert the value of an object to its string representation and to embed that representation in a string. .NET 提供廣泛的格式化支援,在下列格式設定主題中有更詳細的說明:.NET provides extensive formatting support, which is described in greater detail in the following formatting topics:

format參數包含零個或多個與零或多個索引預留位置(稱為格式專案)混合的文字,其對應于此方法之參數清單中的物件。The format parameter consists of zero or more runs of text intermixed with zero or more indexed placeholders, called format items, that correspond to an object in the parameter list of this method. 格式化程式會將每個格式專案取代為對應物件值的字串表示。The formatting process replaces each format item with the string representation of the value of the corresponding object.

格式專案的語法如下:The syntax of a format item is as follows:

{index[,length] [:格式字串]}{index[,length][:formatString]}

在方括號中的元素是選擇性的元素。Elements in square brackets are optional. 下表說明每個元素。The following table describes each element. 如需複合格式功能的詳細資訊,包括格式專案的語法,請參閱複合格式For more information about the composite formatting feature, including the syntax of a format item, see Composite Formatting.

元素Element 說明Description
索引index 要格式化之物件的參數清單中以零為起始的位置。The zero-based position in the parameter list of the object to be formatted. 如果index所指定的物件是null,則會將格式String.Empty專案取代為。If the object specified by index is null, the format item is replaced by String.Empty. 因為此多載在其參數清單中有陣列,所以index的值必須一律小於陣列的長度。Because this overload has an array in its parameter list, the value of index must always be less than the length of the array. 如果索引位置中沒有參數, FormatException則會擲回。If there is no parameter in the index position, a FormatException is thrown.
length,length 參數的字串表示中的最小字元數。The minimum number of characters in the string representation of the parameter. 如果是正數,則參數會靠右對齊;如果是負數,則會靠左對齊。If positive, the parameter is right-aligned; if negative, it is left-aligned.
:formatString:formatString 要格式化之物件所支援的標準或自訂格式字串。A standard or custom format string that is supported by the object to be formatted. 格式字串的可能值與物件的ToString(string format)方法所支援的值相同。Possible values for formatString are the same as the values supported by the object's ToString(string format) method. 如果未指定格式字串,且要IFormattable格式化的物件會執行介面, null format會傳遞做為做為IFormattable.ToString格式字串之參數的值。If formatString is not specified and the object to be formatted implements the IFormattable interface, null is passed as the value of the format parameter that is used as the IFormattable.ToString format string.

開頭和尾端的大括弧字元("{" 和 "}")是必要的。The leading and trailing brace characters, "{" and "}", are required. 若要在中format指定單一常值大括弧字元,請指定兩個開頭或尾端的大括弧字元,也就是 "{{" 或 "}}"。To specify a single literal brace character in format, specify two leading or trailing brace characters; that is, "{{" or "}}".

這個方法不會在指定的字串中搜尋個別的新行字元 (十六進位的 0x000a),也不會以 NewLine 取代它們。This method does not search the specified string for individual newline characters (hexadecimal 0x000a) and replace them with NewLine.

如果格式字串中未參考指定的物件,則會忽略它。If a specified object is not referenced in the format string, it is ignored.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(String, Object) WriteLine(String, Object) WriteLine(String, Object) WriteLine(String, Object)

使用與 Format(String, Object) 方法相同的語意,將格式化字串和新行寫入文字資料流。Writes a formatted string and a new line to the text stream, using the same semantics as the Format(String, Object) method.

public:
 virtual void WriteLine(System::String ^ format, System::Object ^ arg0);
public virtual void WriteLine (string format, object arg0);
abstract member WriteLine : string * obj -> unit
override this.WriteLine : string * obj -> unit
Public Overridable Sub WriteLine (format As String, arg0 As Object)

參數

format
String String String String

複合格式字串。A composite format string.

arg0
Object Object Object Object

要格式化及寫入的物件。The object to format and write.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

format 不是有效的複合格式字串。format is not a valid composite format string.

-或--or- 格式項目的索引小於 0 (零),或大於或等於要格式化的物件數目 (就這個方法多載而言,是一個)。The index of a format item is less than 0 (zero), or greater than or equal to the number of objects to be formatted (which, for this method overload, is one).

備註

這個方法會使用複合格式,將物件的值轉換成其字串表示,並在字串中內嵌該標記法。This method uses composite formatting to convert the value of an object to its string representation and to embed that representation in a string. .NET 提供廣泛的格式化支援,在下列格式設定主題中有更詳細的說明:.NET provides extensive formatting support, which is described in greater detail in the following formatting topics:

format參數包含零個或多個與零或多個索引預留位置(稱為格式專案)混合的文字,其對應于此方法之參數清單中的物件。The format parameter consists of zero or more runs of text intermixed with zero or more indexed placeholders, called format items, that correspond to an object in the parameter list of this method. 格式化程式會將每個格式專案取代為對應物件值的字串表示。The formatting process replaces each format item with the string representation of the value of the corresponding object.

格式專案的語法如下:The syntax of a format item is as follows:

{index[,length] [:格式字串]}{index[,length][:formatString]}

在方括號中的元素是選擇性的元素。Elements in square brackets are optional. 下表說明每個元素。The following table describes each element. 如需複合格式功能的詳細資訊,包括格式專案的語法,請參閱複合格式For more information about the composite formatting feature, including the syntax of a format item, see Composite Formatting.

元素Element 說明Description
索引index 要格式化之物件的參數清單中以零為起始的位置。The zero-based position in the parameter list of the object to be formatted. 如果index所指定的物件是null,則會將格式String.Empty專案取代為。If the object specified by index is null, the format item is replaced by String.Empty. 因為此多載在其參數清單中只有一個物件,所以index的值必須一律為0。Because this overload has only a single object in its parameter list, the value of index must always be 0. 如果索引位置中沒有參數, FormatException則會擲回。If there is no parameter in the index position, a FormatException is thrown.
length,length 參數的字串表示中的最小字元數。The minimum number of characters in the string representation of the parameter. 如果是正數,則參數會靠右對齊;如果是負數,則會靠左對齊。If positive, the parameter is right-aligned; if negative, it is left-aligned.
:formatString:formatString 要格式化之物件所支援的標準或自訂格式字串。A standard or custom format string that is supported by the object to be formatted. 格式字串的可能值與物件的ToString(string format)方法所支援的值相同。Possible values for formatString are the same as the values supported by the object's ToString(string format) method. 如果未指定格式字串,且要IFormattable格式化的物件會執行介面, null format會傳遞做為做為IFormattable.ToString格式字串之參數的值。If formatString is not specified and the object to be formatted implements the IFormattable interface, null is passed as the value of the format parameter that is used as the IFormattable.ToString format string.

開頭和尾端的大括弧字元("{" 和 "}")是必要的。The leading and trailing brace characters, "{" and "}", are required. 若要在中format指定單一常值大括弧字元,請指定兩個開頭或尾端的大括弧字元,也就是 "{{" 或 "}}"。To specify a single literal brace character in format, specify two leading or trailing brace characters; that is, "{{" or "}}".

這個方法不會在指定的字串中搜尋個別的新行字元 (十六進位的 0x000a),也不會以 NewLine 取代它們。This method does not search the specified string for individual newline characters (hexadecimal 0x000a) and replace them with NewLine.

如果格式字串中未參考指定的物件,則會忽略它。If a specified object is not referenced in the format string, it is ignored.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(UInt64) WriteLine(UInt64) WriteLine(UInt64) WriteLine(UInt64)

重要

此 API 不符合 CLS 規範。

將 8 位元組不帶正負號的整數文字表示寫入文字資料流,後接行結束字元。Writes the text representation of an 8-byte unsigned integer to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(System::UInt64 value);
[System.CLSCompliant(false)]
public virtual void WriteLine (ulong value);
abstract member WriteLine : uint64 -> unit
override this.WriteLine : uint64 -> unit
Public Overridable Sub WriteLine (value As ULong)

參數

value
UInt64 UInt64 UInt64 UInt64

要寫入之 8 位元組不帶正負號的整數。The 8-byte unsigned integer to write.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

指定值的文字表示是藉由呼叫UInt64.ToString方法所產生。The text representation of the specified value is produced by calling the UInt64.ToString method. 屬性(如果不是null)會指定文化特性特定的格式。 FormatProviderThe FormatProvider property, if not null, specifies the culture-specific formatting.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(UInt32) WriteLine(UInt32) WriteLine(UInt32) WriteLine(UInt32)

重要

此 API 不符合 CLS 規範。

將 4 位元組不帶正負號的整數文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(System::UInt32 value);
[System.CLSCompliant(false)]
public virtual void WriteLine (uint value);
abstract member WriteLine : uint32 -> unit
override this.WriteLine : uint32 -> unit
Public Overridable Sub WriteLine (value As UInteger)

參數

value
UInt32 UInt32 UInt32 UInt32

要寫入之 4 位元組不帶正負號的整數。The 4-byte unsigned integer to write.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

指定值的文字表示是藉由呼叫UInt32.ToString方法所產生。The text representation of the specified value is produced by calling the UInt32.ToString method. 屬性(如果不是null)會指定文化特性特定的格式。 FormatProviderThe FormatProvider property, if not null, specifies the culture-specific formatting.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(String, Object, Object, Object) WriteLine(String, Object, Object, Object) WriteLine(String, Object, Object, Object) WriteLine(String, Object, Object, Object)

使用與 Format(String, Object) 相同的語意,寫出文字資料流中的格式化字串和新行。Writes out a formatted string and a new line to the text stream, using the same semantics as Format(String, Object).

public:
 virtual void WriteLine(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2);
public virtual void WriteLine (string format, object arg0, object arg1, object arg2);
abstract member WriteLine : string * obj * obj * obj -> unit
override this.WriteLine : string * obj * obj * obj -> unit
Public Overridable Sub WriteLine (format As String, arg0 As Object, arg1 As Object, arg2 As Object)

參數

format
String String String String

複合格式字串。A composite format string.

arg0
Object Object Object Object

第一個要格式化和寫入的物件。The first object to format and write.

arg1
Object Object Object Object

第二個要格式化和寫入的物件。The second object to format and write.

arg2
Object Object Object Object

第三個要格式化和寫入的物件。The third object to format and write.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

format 不是有效的複合格式字串。format is not a valid composite format string.

-或--or- 格式項目的索引小於 0 (零),或大於或等於要格式化的物件數目 (就這個方法多載而言,是三個)。The index of a format item is less than 0 (zero), or greater than or equal to the number of objects to be formatted (which, for this method overload, is three).

備註

這個方法會使用複合格式,將物件的值轉換成其字串表示,並在字串中內嵌該標記法。This method uses composite formatting to convert the value of an object to its string representation and to embed that representation in a string. .NET 提供廣泛的格式化支援,在下列格式設定主題中有更詳細的說明:.NET provides extensive formatting support, which is described in greater detail in the following formatting topics:

format參數包含零個或多個與零或多個索引預留位置(稱為格式專案)混合的文字,其對應于此方法之參數清單中的物件。The format parameter consists of zero or more runs of text intermixed with zero or more indexed placeholders, called format items, that correspond to an object in the parameter list of this method. 格式化程式會將每個格式專案取代為對應物件值的字串表示。The formatting process replaces each format item with the string representation of the value of the corresponding object.

格式專案的語法如下:The syntax of a format item is as follows:

{index[,length] [:格式字串]}{index[,length][:formatString]}

在方括號中的元素是選擇性的元素。Elements in square brackets are optional. 下表說明每個元素。The following table describes each element. 如需複合格式功能的詳細資訊,包括格式專案的語法,請參閱複合格式For more information about the composite formatting feature, including the syntax of a format item, see Composite Formatting.

元素Element 說明Description
索引index 要格式化之物件的參數清單中以零為起始的位置。The zero-based position in the parameter list of the object to be formatted. 如果index所指定的物件是null,則會將格式String.Empty專案取代為。If the object specified by index is null, the format item is replaced by String.Empty. 因為此多載在其參數清單中有三個物件,所以index的值必須一律為0、1或2。Because this overload has three objects in its parameter list, the value of index must always be 0, 1, or 2. 如果索引位置中沒有參數, FormatException則會擲回。If there is no parameter in the index position, a FormatException is thrown.
length,length 參數的字串表示中的最小字元數。The minimum number of characters in the string representation of the parameter. 如果是正數,則參數會靠右對齊;如果是負數,則會靠左對齊。If positive, the parameter is right-aligned; if negative, it is left-aligned.
:formatString:formatString 要格式化之物件所支援的標準或自訂格式字串。A standard or custom format string that is supported by the object to be formatted. 格式字串的可能值與物件的ToString(string format)方法所支援的值相同。Possible values for formatString are the same as the values supported by the object's ToString(string format) method. 如果未指定格式字串,且要IFormattable格式化的物件會執行介面, null format會傳遞做為做為IFormattable.ToString格式字串之參數的值。If formatString is not specified and the object to be formatted implements the IFormattable interface, null is passed as the value of the format parameter that is used as the IFormattable.ToString format string.

開頭和尾端的大括弧字元("{" 和 "}")是必要的。The leading and trailing brace characters, "{" and "}", are required. 若要在中format指定單一常值大括弧字元,請指定兩個開頭或尾端的大括弧字元,也就是 "{{" 或 "}}"。To specify a single literal brace character in format, specify two leading or trailing brace characters; that is, "{{" or "}}".

這個方法不會在指定的字串中搜尋個別的新行字元 (十六進位的 0x000a),也不會以 NewLine 取代它們。This method does not search the specified string for individual newline characters (hexadecimal 0x000a) and replace them with NewLine.

如果格式字串中未參考指定的物件,則會忽略它。If a specified object is not referenced in the format string, it is ignored.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(StringBuilder) WriteLine(StringBuilder) WriteLine(StringBuilder) WriteLine(StringBuilder)

將字串產生器的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a string builder to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(System::Text::StringBuilder ^ value);
public virtual void WriteLine (System.Text.StringBuilder value);
abstract member WriteLine : System.Text.StringBuilder -> unit
override this.WriteLine : System.Text.StringBuilder -> unit
Public Overridable Sub WriteLine (value As StringBuilder)

參數

value
StringBuilder StringBuilder StringBuilder StringBuilder

作為字串產生器的字串,用於寫入文字資料流。The string, as a string builder, to write to the text stream.

備註

指定值的文字表示是藉由呼叫StringBuilder.ToString方法所產生。The text representation of the specified value is produced by calling the StringBuilder.ToString method.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

WriteLine(String) WriteLine(String) WriteLine(String) WriteLine(String)

將字串寫入文字資料流,後接行結束字元。Writes a string to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(System::String ^ value);
public virtual void WriteLine (string value);
abstract member WriteLine : string -> unit
override this.WriteLine : string -> unit
Public Overridable Sub WriteLine (value As String)

參數

value
String String String String

要寫入的字串。The string to write. 如果 valuenull,只寫入行結束字元。If value is null, only the line terminator is written.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

這個多載相當於Write(Char[])多載。This overload is equivalent to the Write(Char[]) overload.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

這個方法不會在指定的字串中搜尋個別的新行字元 (十六進位的 0x000a),也不會以 NewLine 取代它們。This method does not search the specified string for individual newline characters (hexadecimal 0x000a) and replace them with NewLine.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(Single) WriteLine(Single) WriteLine(Single) WriteLine(Single)

將 4 位元組浮點數值的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a 4-byte floating-point value to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(float value);
public virtual void WriteLine (float value);
abstract member WriteLine : single -> unit
override this.WriteLine : single -> unit
Public Overridable Sub WriteLine (value As Single)

參數

value
Single Single Single Single

要寫入的 4 位元組浮點數值。The 4-byte floating-point value to write.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

屬性(如果不是null)會指定文化特性特定的格式。 FormatProviderThe FormatProvider property, if not null, specifies the culture-specific formatting. 如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

另請參閱

WriteLine(Double) WriteLine(Double) WriteLine(Double) WriteLine(Double)

將 8 位元組浮點數值的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a 8-byte floating-point value to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(double value);
public virtual void WriteLine (double value);
abstract member WriteLine : double -> unit
override this.WriteLine : double -> unit
Public Overridable Sub WriteLine (value As Double)

參數

value
Double Double Double Double

要寫入的 8 位元組浮點數值。The 8-byte floating-point value to write.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

屬性(如果不是null)會指定文化特性特定的格式。 FormatProviderThe FormatProvider property, if not null, specifies the culture-specific formatting. 如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

另請參閱

WriteLine(Object) WriteLine(Object) WriteLine(Object) WriteLine(Object)

藉由呼叫該物件上的 ToString 方法,後接行結束字元,將物件的文字表示寫入文字資料流。Writes the text representation of an object to the text stream, by calling the ToString method on that object, followed by a line terminator.

public:
 virtual void WriteLine(System::Object ^ value);
public virtual void WriteLine (object value);
abstract member WriteLine : obj -> unit
override this.WriteLine : obj -> unit
Public Overridable Sub WriteLine (value As Object)

參數

value
Object Object Object Object

要寫入的物件。The object to write. 如果 valuenull,只寫入行結束字元。If value is null, only the line terminator is written.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

這個多載相當於Write(String, Object)多載。This overload is equivalent to the Write(String, Object) overload. 屬性(如果不是null)會指定文化特性特定的格式。 FormatProviderThe FormatProvider property, if not null, specifies the culture-specific formatting.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(Int64) WriteLine(Int64) WriteLine(Int64) WriteLine(Int64)

將 8 位元組帶正負號的整數文字表示寫入文字資料流,後接行結束字元。Writes the text representation of an 8-byte signed integer to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(long value);
public virtual void WriteLine (long value);
abstract member WriteLine : int64 -> unit
override this.WriteLine : int64 -> unit
Public Overridable Sub WriteLine (value As Long)

參數

value
Int64 Int64 Int64 Int64

要寫入之 8 位元組帶正負號的整數。The 8-byte signed integer to write.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

指定值的文字表示是藉由呼叫Int64.ToString方法所產生。The text representation of the specified value is produced by calling the Int64.ToString method. 屬性(如果不是null)會指定文化特性特定的格式。 TextWriter.FormatProviderThe TextWriter.FormatProvider property, if not null, specifies the culture-specific formatting.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(Int32) WriteLine(Int32) WriteLine(Int32) WriteLine(Int32)

將 4 位元組帶正負號的整數文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(int value);
public virtual void WriteLine (int value);
abstract member WriteLine : int -> unit
override this.WriteLine : int -> unit
Public Overridable Sub WriteLine (value As Integer)

參數

value
Int32 Int32 Int32 Int32

要寫入之 4 位元組帶正負號的整數。The 4-byte signed integer to write.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

指定值的文字表示是藉由呼叫Int32.ToString方法所產生。The text representation of the specified value is produced by calling the Int32.ToString method. 屬性(如果不是null)會指定文化特性特定的格式。 TextWriter.FormatProviderThe TextWriter.FormatProvider property, if not null, specifies the culture-specific formatting.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(Decimal) WriteLine(Decimal) WriteLine(Decimal) WriteLine(Decimal)

將十進位值的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a decimal value to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(System::Decimal value);
public virtual void WriteLine (decimal value);
abstract member WriteLine : decimal -> unit
override this.WriteLine : decimal -> unit
Public Overridable Sub WriteLine (value As Decimal)

參數

value
Decimal Decimal Decimal Decimal

要寫入的十進位值。The decimal value to write.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

屬性(如果不是null)會指定文化特性特定的格式。 FormatProviderThe FormatProvider property, if not null, specifies the culture-specific formatting. 如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

另請參閱

WriteLine(Char[]) WriteLine(Char[]) WriteLine(Char[]) WriteLine(Char[])

將字元的陣列寫入文字資料流,後接行結束字元。Writes an array of characters to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(cli::array <char> ^ buffer);
public virtual void WriteLine (char[] buffer);
abstract member WriteLine : char[] -> unit
override this.WriteLine : char[] -> unit
Public Overridable Sub WriteLine (buffer As Char())

參數

buffer
Char[]

資料讀取來源的字元陣列。The character array from which data is read.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

buffer的所有字元都會寫入基礎資料流程。All the characters in buffer are written to the underlying stream. 如果字元陣列是 null,則只有行結束字元會被寫入。If the character array is null, only the line terminator is written.

這個多載相當於Write(Char[]) WriteLine()後面接著。This overload is equivalent to Write(Char[]) followed by WriteLine() .

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(Char) WriteLine(Char) WriteLine(Char) WriteLine(Char)

將字元寫入文字資料流,後接行結束字元。Writes a character to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(char value);
public virtual void WriteLine (char value);
abstract member WriteLine : char -> unit
override this.WriteLine : char -> unit
Public Overridable Sub WriteLine (value As Char)

參數

value
Char Char Char Char

要寫入到文字資料流的字元。The character to write to the text stream.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

這個多載相當於Write(Char) WriteLine()後面接著。This overload is equivalent to Write(Char) followed by WriteLine() .

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(Boolean) WriteLine(Boolean) WriteLine(Boolean) WriteLine(Boolean)

Boolean 值的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a Boolean value to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(bool value);
public virtual void WriteLine (bool value);
abstract member WriteLine : bool -> unit
override this.WriteLine : bool -> unit
Public Overridable Sub WriteLine (value As Boolean)

參數

value
Boolean Boolean Boolean Boolean

要寫入的 Boolean 值。The Boolean value to write.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

指定值的文字表示是藉由呼叫Boolean.ToString方法所產生。The text representation of the specified value is produced by calling the Boolean.ToString method.

這個方法會輸出Boolean.TrueStringBoolean.FalseStringThis method outputs either Boolean.TrueString or Boolean.FalseString.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine() WriteLine() WriteLine() WriteLine()

將行結束字元寫入文字資料流。Writes a line terminator to the text stream.

public:
 virtual void WriteLine();
public virtual void WriteLine ();
abstract member WriteLine : unit -> unit
override this.WriteLine : unit -> unit
Public Overridable Sub WriteLine ()

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

另請參閱

WriteLine(ReadOnlySpan<Char>) WriteLine(ReadOnlySpan<Char>) WriteLine(ReadOnlySpan<Char>) WriteLine(ReadOnlySpan<Char>)

將字元範圍的文字表示寫入文字資料流,後接行結束字元。Writes the text representation of a character span to the text stream, followed by a line terminator.

public:
 virtual void WriteLine(ReadOnlySpan<char> buffer);
public virtual void WriteLine (ReadOnlySpan<char> buffer);
abstract member WriteLine : ReadOnlySpan<char> -> unit
override this.WriteLine : ReadOnlySpan<char> -> unit
Public Overridable Sub WriteLine (buffer As ReadOnlySpan(Of Char))

參數

buffer
ReadOnlySpan<Char>

要寫入文字資料流的字元範圍值。The char span value to write to the text stream.

備註

指定值的文字表示會藉由呼叫ReadOnlySpan來產生。ToString方法。The text representation of the specified value is produced by calling the ReadOnlySpan.ToString method.

行結束字元是由 CoreNewLine 欄位所定義。The line terminator is defined by the CoreNewLine field.

如需一般 i/o 工作的清單, 請參閱一般 i/o工作。For a list of common I/O tasks, see Common I/O Tasks.

適用於