TextWriter.Write TextWriter.Write TextWriter.Write TextWriter.Write Method

定義

將資料寫入文字資料流。Writes data to a text stream.

多載

Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object)

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

Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32)

將字元的子陣列寫入至文字資料流。Writes a subarray of characters to the text stream.

Write(String, Object[]) Write(String, Object[]) Write(String, Object[]) Write(String, Object[])

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

Write(String, Object) Write(String, Object) Write(String, Object) Write(String, Object)

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

Write(UInt64) Write(UInt64) Write(UInt64) Write(UInt64)

將 8 位元組帶不正負號的整數文字表示寫入文字資料流。Writes the text representation of an 8-byte unsigned integer to the text stream.

Write(UInt32) Write(UInt32) Write(UInt32) Write(UInt32)

將 4 位元組不帶正負號的整數文字表示寫入文字資料流。Writes the text representation of a 4-byte unsigned integer to the text stream.

Write(StringBuilder) Write(StringBuilder) Write(StringBuilder) Write(StringBuilder)

將字串產生器寫入文字資料流。Writes a string builder to the text stream.

Write(String) Write(String) Write(String) Write(String)

將字串寫入到文字資料流。Writes a string to the text stream.

Write(Single) Write(Single) Write(Single) Write(Single)

將 4 位元組浮點數值的文字表示寫入文字資料流。Writes the text representation of a 4-byte floating-point value to the text stream.

Write(String, Object, Object, Object) Write(String, Object, Object, Object) Write(String, Object, Object, Object) Write(String, Object, Object, Object)

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

Write(Object) Write(Object) Write(Object) Write(Object)

呼叫該物件的 ToString 方法,將物件的文字表示寫入文字資料流。Writes the text representation of an object to the text stream by calling the ToString method on that object.

Write(Int64) Write(Int64) Write(Int64) Write(Int64)

將 8 位元組帶正負號的整數文字表示寫入文字資料流。Writes the text representation of an 8-byte signed integer to the text stream.

Write(Int32) Write(Int32) Write(Int32) Write(Int32)

將 4 位元組帶正負號的整數文字表示寫入文字資料流。Writes the text representation of a 4-byte signed integer to the text stream.

Write(Double) Write(Double) Write(Double) Write(Double)

將 8 位元組浮點數值的文字表示寫入文字資料流。Writes the text representation of an 8-byte floating-point value to the text stream.

Write(Decimal) Write(Decimal) Write(Decimal) Write(Decimal)

將十進位值的文字表示寫入文字資料流。Writes the text representation of a decimal value to the text stream.

Write(Char[]) Write(Char[]) Write(Char[]) Write(Char[])

將字元陣列寫入文字資料流。Writes a character array to the text stream.

Write(Char) Write(Char) Write(Char) Write(Char)

將字元寫入文字資料流。Writes a character to the text stream.

Write(Boolean) Write(Boolean) Write(Boolean) Write(Boolean)

Boolean 值的文字表示寫入文字資料流。Writes the text representation of a Boolean value to the text stream.

Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>)

將字元範圍寫入文字資料流。Writes a character span to the text stream.

Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object) Write(String, Object, Object)

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

public:
 virtual void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1);
public virtual void Write (string format, object arg0, object arg1);
abstract member Write : string * obj * obj -> unit
override this.Write : string * obj * obj -> unit
Public Overridable Sub Write (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),也不會以 TextWriter.NewLine 取代它們。This method does not search the specified string for individual newline characters (hexadecimal 0x000a) and replace them with TextWriter.NewLine.

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

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

另請參閱

Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32) Write(Char[], Int32, Int32)

將字元的子陣列寫入至文字資料流。Writes a subarray of characters to the text stream.

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

參數

buffer
Char[]

資料寫入來源的字元陣列。The character array to write data from.

index
Int32 Int32 Int32 Int32

緩衝區中要開始擷取資料的字元位置。The character position in the buffer at which to start retrieving data.

count
Int32 Int32 Int32 Int32

要寫入的字元數。The 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[])index index buffer )之間每count個字元的多載。 + This overload is equivalent to the Write(Char[]) overload for each character in buffer between index and (index + count).

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

另請參閱

Write(String, Object[]) Write(String, Object[]) Write(String, Object[]) Write(String, Object[])

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

public:
 virtual void Write(System::String ^ format, ... cli::array <System::Object ^> ^ arg);
public virtual void Write (string format, params object[] arg);
abstract member Write : string * obj[] -> unit
override this.Write : string * obj[] -> unit
Public Overridable Sub Write (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.

例外狀況

發生 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),也不會以 TextWriter.NewLine 取代它們。This method does not search the specified string for individual newline characters (hexadecimal 0x000a) and replace them with TextWriter.NewLine.

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

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

另請參閱

Write(String, Object) Write(String, Object) Write(String, Object) Write(String, Object)

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

public:
 virtual void Write(System::String ^ format, System::Object ^ arg0);
public virtual void Write (string format, object arg0);
abstract member Write : string * obj -> unit
override this.Write : string * obj -> unit
Public Overridable Sub Write (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 "}}".

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

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

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

另請參閱

Write(UInt64) Write(UInt64) Write(UInt64) Write(UInt64)

重要

此 API 不符合 CLS 規範。

將 8 位元組帶不正負號的整數文字表示寫入文字資料流。Writes the text representation of an 8-byte unsigned integer to the text stream.

public:
 virtual void Write(System::UInt64 value);
[System.CLSCompliant(false)]
public virtual void Write (ulong value);
abstract member Write : uint64 -> unit
override this.Write : uint64 -> unit
Public Overridable Sub Write (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)會指定文化特性特定的格式。 TextWriter.FormatProviderThe TextWriter.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.

另請參閱

Write(UInt32) Write(UInt32) Write(UInt32) Write(UInt32)

重要

此 API 不符合 CLS 規範。

將 4 位元組不帶正負號的整數文字表示寫入文字資料流。Writes the text representation of a 4-byte unsigned integer to the text stream.

public:
 virtual void Write(System::UInt32 value);
[System.CLSCompliant(false)]
public virtual void Write (uint value);
abstract member Write : uint32 -> unit
override this.Write : uint32 -> unit
Public Overridable Sub Write (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)會指定文化特性特定的格式。 TextWriter.FormatProviderThe TextWriter.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.

另請參閱

Write(StringBuilder) Write(StringBuilder) Write(StringBuilder) Write(StringBuilder)

將字串產生器寫入文字資料流。Writes a string builder to the text stream.

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

參數

value
StringBuilder StringBuilder StringBuilder StringBuilder

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

備註

這個方法相當於Write(stringBuilder.ToString()),但它會StringBuilder.GetChunks使用方法來避免建立中繼字串。This method is equivalent to Write(stringBuilder.ToString()), but it uses the StringBuilder.GetChunks method to avoid creating the intermediate string.

Write(String) Write(String) Write(String) Write(String)

將字串寫入到文字資料流。Writes a string to the text stream.

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

參數

value
String String String String

要寫入的字串。The string to write.

例外狀況

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

備註

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

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

如果 valuenull,不寫入任何字串到文字資料流。If value is null, nothing is written to the text stream.

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

另請參閱

Write(Single) Write(Single) Write(Single) Write(Single)

將 4 位元組浮點數值的文字表示寫入文字資料流。Writes the text representation of a 4-byte floating-point value to the text stream.

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

參數

value
Single Single Single Single

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

例外狀況

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

備註

指定值的文字表示是藉由呼叫Single.ToString方法所產生。The text representation of the specified value is produced by calling the Single.ToString method. 屬性(如果不是null)會指定文化特性特定的格式。 TextWriter.FormatProviderThe TextWriter.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.

另請參閱

Write(String, Object, Object, Object) Write(String, Object, Object, Object) Write(String, Object, Object, Object) Write(String, Object, Object, Object)

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

public:
 virtual void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2);
public virtual void Write (string format, object arg0, object arg1, object arg2);
abstract member Write : string * obj * obj * obj -> unit
override this.Write : string * obj * obj * obj -> unit
Public Overridable Sub Write (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),並將TextWriter.NewLine其取代為。This method does not search the specified string for individual newline characters (hexadecimal 0x000a) and replace them with TextWriter.NewLine.

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

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

另請參閱

Write(Object) Write(Object) Write(Object) Write(Object)

呼叫該物件的 ToString 方法,將物件的文字表示寫入文字資料流。Writes the text representation of an object to the text stream by calling the ToString method on that object.

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

參數

value
Object Object Object Object

要寫入的物件。The object to write.

例外狀況

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

備註

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

如果指定的物件是null,則不會採取任何動作,也不會擲回任何例外狀況。If the specified object is null, no action is taken and no exception is thrown. 否則,會呼叫物件ToString的方法來產生字串表示,然後將產生的字串寫入輸出資料流程。Otherwise, the object's ToString method is called to produce the string representation, and the resulting string is then written to the output stream. 屬性(如果不是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.

另請參閱

Write(Int64) Write(Int64) Write(Int64) Write(Int64)

將 8 位元組帶正負號的整數文字表示寫入文字資料流。Writes the text representation of an 8-byte signed integer to the text stream.

public:
 virtual void Write(long value);
public virtual void Write (long value);
abstract member Write : int64 -> unit
override this.Write : int64 -> unit
Public Overridable Sub Write (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.

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

如何:將文字寫入檔案How to: Write Text to a File

另請參閱

Write(Int32) Write(Int32) Write(Int32) Write(Int32)

將 4 位元組帶正負號的整數文字表示寫入文字資料流。Writes the text representation of a 4-byte signed integer to the text stream.

public:
 virtual void Write(int value);
public virtual void Write (int value);
abstract member Write : int -> unit
override this.Write : int -> unit
Public Overridable Sub Write (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.

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

另請參閱

Write(Double) Write(Double) Write(Double) Write(Double)

將 8 位元組浮點數值的文字表示寫入文字資料流。Writes the text representation of an 8-byte floating-point value to the text stream.

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

參數

value
Double Double Double Double

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

例外狀況

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

備註

指定值的文字表示是藉由呼叫Double.ToString方法所產生。The text representation of the specified value is produced by calling the Double.ToString method. 屬性(如果不是null)會指定文化特性特定的格式。 TextWriter.FormatProviderThe TextWriter.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.

另請參閱

Write(Decimal) Write(Decimal) Write(Decimal) Write(Decimal)

將十進位值的文字表示寫入文字資料流。Writes the text representation of a decimal value to the text stream.

public:
 virtual void Write(System::Decimal value);
public virtual void Write (decimal value);
abstract member Write : decimal -> unit
override this.Write : decimal -> unit
Public Overridable Sub Write (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.

另請參閱

Write(Char[]) Write(Char[]) Write(Char[]) Write(Char[])

將字元陣列寫入文字資料流。Writes a character array to the text stream.

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

參數

buffer
Char[]

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

例外狀況

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

備註

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

這個預設方法會呼叫Write(Char[], Int32, Int32)方法,並傳遞整個字元陣列。This default method calls the Write(Char[], Int32, Int32) method and passes the entire character array. 如果字元陣列是null,則不會寫入任何內容。If the character array is null, nothing is written.

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

另請參閱

Write(Char) Write(Char) Write(Char) Write(Char)

將字元寫入文字資料流。Writes a character to the text stream.

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

參數

value
Char Char Char Char

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

例外狀況

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

備註

這個預設方法不會執行任何工作,但衍生的類別可以覆寫方法來提供適當的功能。This default method does nothing, but derived classes can override the method to provide the appropriate functionality.

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

另請參閱

Write(Boolean) Write(Boolean) Write(Boolean) Write(Boolean)

Boolean 值的文字表示寫入文字資料流。Writes the text representation of a Boolean value to the text stream.

public:
 virtual void Write(bool value);
public virtual void Write (bool value);
abstract member Write : bool -> unit
override this.Write : bool -> unit
Public Overridable Sub Write (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.

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

另請參閱

Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>) Write(ReadOnlySpan<Char>)

將字元範圍寫入文字資料流。Writes a character span to the text stream.

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

參數

buffer
ReadOnlySpan<Char>

要寫入的字元範圍。The character span to write.

備註

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

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

適用於