TextWriter.WriteLine 方法

定义

将数据写入文本流,后跟行终止符。Writes data to the text stream, followed by a line terminator.

重载

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)

将字符子数组写入文本流,后跟行终止符。Writes a subarray of characters to the text stream, followed by a line terminator.

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)

使用与 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)

将 8 字节无符号整数的文本表示形式写入文本流,后跟行终止符。Writes the text representation of an 8-byte unsigned integer to the text stream, followed by a line terminator.

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)

使用与 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)

将字符串生成器的文本表示形式写入文本流,后跟行终止符。Writes the text representation of a string builder to the text stream, followed by a line terminator.

WriteLine(String)

将字符串写入文本流,后跟行终止符。Writes a string to the text stream, followed by a line terminator.

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)

将 8 字节浮点值的文本表示形式写入文本流,后跟行终止符。Writes the text representation of a 8-byte floating-point value to the text stream, followed by a line terminator.

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)

将 8 字节带符号整数的文本表示形式写入文本流,后跟行终止符。Writes the text representation of an 8-byte signed integer to the text stream, followed by a line terminator.

WriteLine(Int32)

将 4 字节带符号整数的文本表示形式写入文本流,后跟行终止符。Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator.

WriteLine(Decimal)

将小数值的文本表示形式写入文本流,后跟行终止符。Writes the text representation of a decimal value to the text stream, followed by a line terminator.

WriteLine(Char[])

将字符数组写入文本流,后跟行终止符。Writes an array of characters to the text stream, followed by a line terminator.

WriteLine(Char)

将字符写入文本流,后跟行终止符。Writes a character to the text stream, followed by a line terminator.

WriteLine(Boolean)

Boolean 值的文本表示形式写入文本流,后跟行终止符。Writes the text representation of a Boolean value to the text stream, followed by a line terminator.

WriteLine()

将行终止符写入文本流。Writes a line terminator to the text stream.

WriteLine(ReadOnlySpan<Char>)

将字符范围的文本表示形式写入文本流,后跟行终止符。Writes the text representation of a character span to the text stream, followed by a line terminator.

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

复合格式字符串。A composite format string.

arg0
Object

要格式化和写入的第一个对象。The first object to format and write.

arg1
Object

要格式化和写入的第二个对象。The second object to format and write.

异常

formatnullformat is null.

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

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

- 或 --or- 格式项的索引小于 0 (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)

将字符子数组写入文本流,后跟行终止符。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

在开始读取数据时 buffer 中的字符位置。The character position in buffer at which to start reading data.

count
Int32

要写入的最大字符数。The maximum number of characters to write.

异常

缓冲区长度减去 index 小于 countThe buffer length minus index is less than count.

buffer 参数为 nullThe buffer parameter is null.

indexcount 为负数。index or count is negative.

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

注解

此方法将数据count从位置buffer index开始的字符TextWriter数组写入到此中。This method will write count characters of data into this TextWriter from the buffer character array starting at position index.

此重载等效于调用Write(Char[])方法, WriteLine后跟和( + buffer index index)之间的每个字符countThis 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[])

使用与 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

复合格式字符串。A composite format string.

arg
Object[]

一个对象数组,其中包含零个或多个要设置格式和写入的对象。An object array that contains zero or more objects to format and write.

异常

字符串或对象作为 null 传入。A string or object is passed in as null.

TextWriter 是关闭的。The TextWriter is closed.

出现 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)

使用与 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

复合格式字符串。A composite format string.

arg0
Object

要格式化和写入的对象。The object to format and write.

异常

formatnullformat is null.

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

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

-or- 格式项的索引小于 0 (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)

重要

此 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

要写入的 8 字节无符号整数。The 8-byte unsigned integer to write.

属性

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

注解

通过调用UInt64.ToString方法来生成指定值的文本表示形式。The text representation of the specified value is produced by calling the UInt64.ToString method. 如果FormatProvidernull是,则属性指定区域性特定的格式设置。The 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)

重要

此 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

要写入的 4 字节无符号整数。The 4-byte unsigned integer to write.

属性

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

注解

通过调用UInt32.ToString方法来生成指定值的文本表示形式。The text representation of the specified value is produced by calling the UInt32.ToString method. 如果FormatProvidernull是,则属性指定区域性特定的格式设置。The 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)

使用与 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

复合格式字符串。A composite format string.

arg0
Object

要格式化和写入的第一个对象。The first object to format and write.

arg1
Object

要格式化和写入的第二个对象。The second object to format and write.

arg2
Object

要设置格式和写入的第三个对象。The third object to format and write.

异常

formatnullformat is null.

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

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

-or- 格式项的索引小于 0 (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)

将字符串生成器的文本表示形式写入文本流,后跟行终止符。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

要作为字符串生成器写入文本流的字符串。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)

将字符串写入文本流,后跟行终止符。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

要写入的字符串。The string to write. 如果 valuenull,则只写入行终止符。If value is null, only the line terminator is written.

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 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)

将 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

要写入的 4 字节浮点值。The 4-byte floating-point value to write.

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

注解

如果FormatProvidernull是,则属性指定区域性特定的格式设置。The 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)

将 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

要写入的 8 字节浮点值。The 8-byte floating-point value to write.

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

注解

如果FormatProvidernull是,则属性指定区域性特定的格式设置。The 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)

通过在对象上调用 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

要写入的对象。The object to write. 如果 valuenull,则只写入行终止符。If value is null, only the line terminator is written.

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

注解

此重载等效于Write(String, Object)重载。This overload is equivalent to the Write(String, Object) overload. 如果FormatProvidernull是,则属性指定区域性特定的格式设置。The 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)

将 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

要写入的 8 字节有符号整数。The 8-byte signed integer to write.

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

注解

通过调用Int64.ToString方法来生成指定值的文本表示形式。The text representation of the specified value is produced by calling the Int64.ToString method. 如果TextWriter.FormatProvidernull是,则属性指定区域性特定的格式设置。The 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)

将 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

要写入的 4 字节有符号整数。The 4-byte signed integer to write.

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

注解

通过调用Int32.ToString方法来生成指定值的文本表示形式。The text representation of the specified value is produced by calling the Int32.ToString method. 如果TextWriter.FormatProvidernull是,则属性指定区域性特定的格式设置。The 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)

将小数值的文本表示形式写入文本流,后跟行终止符。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

要写入的十进制值。The decimal value to write.

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 I/O 错误。An I/O error occurs.

注解

如果FormatProvidernull是,则属性指定区域性特定的格式设置。The 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[])

将字符数组写入文本流,后跟行终止符。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.

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 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)

将字符写入文本流,后跟行终止符。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

要写入文本流中的字符。The character to write to the text stream.

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 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)

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 值。The Boolean value to write.

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 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()

将行终止符写入文本流。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 ()

异常

TextWriter 是关闭的。The TextWriter is closed.

出现 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>)

将字符范围的文本表示形式写入文本流,后跟行终止符。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.

适用于