TextReader.Read TextReader.Read TextReader.Read TextReader.Read Method

定义

从文本读取器读取数据。Reads data from the text reader.

重载

Read() Read() Read() Read()

读取文本读取器中的下一个字符并使该字符的位置提升一个字符。Reads the next character from the text reader and advances the character position by one character.

Read(Span<Char>) Read(Span<Char>) Read(Span<Char>) Read(Span<Char>)
Read(Char[], Int32, Int32) Read(Char[], Int32, Int32) Read(Char[], Int32, Int32) Read(Char[], Int32, Int32)

从当前读取器中读取指定数目的字符并从指定索引开始将该数据写入缓冲区。Reads a specified maximum number of characters from the current reader and writes the data to a buffer, beginning at the specified index.

Read() Read() Read() Read()

读取文本读取器中的下一个字符并使该字符的位置提升一个字符。Reads the next character from the text reader and advances the character position by one character.

public:
 virtual int Read();
public virtual int Read ();
abstract member Read : unit -> int
override this.Read : unit -> int
Public Overridable Function Read () As Integer

返回

文本读取器中的下一个字符,或为 -1 (如果没有更多的可用字符)。The next character from the text reader, or -1 if no more characters are available. 默认实现将返回 -1。The default implementation returns -1.

异常

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

注解

TextReader 类是抽象类。The TextReader class is an abstract class. 因此,您实例化它在代码中。Therefore, you do not instantiate it in your code. 有关使用的示例Read方法,请参阅StreamReader.Read方法。For an example of using the Read method, see the StreamReader.Read method.

另请参阅

Read(Span<Char>) Read(Span<Char>) Read(Span<Char>) Read(Span<Char>)

public:
 virtual int Read(Span<char> buffer);
public virtual int Read (Span<char> buffer);
abstract member Read : Span<char> -> int
override this.Read : Span<char> -> int
Public Overridable Function Read (buffer As Span(Of Char)) As Integer

参数

buffer
Span<Char>

返回

Read(Char[], Int32, Int32) Read(Char[], Int32, Int32) Read(Char[], Int32, Int32) Read(Char[], Int32, Int32)

从当前读取器中读取指定数目的字符并从指定索引开始将该数据写入缓冲区。Reads a specified maximum number of characters from the current reader and writes the data to a buffer, beginning at the specified index.

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

参数

buffer
Char[]

当此方法返回时,包含指定的字符数组,此数组中 index 和 (index + count - 1) 之间的值被从当前源中读取的字符所替换。When this method returns, contains the specified character array with the values between index and (index + count - 1) replaced by the characters read from the current source.

index
Int32 Int32 Int32 Int32

buffer 中开始写入的位置。The position in buffer at which to begin writing.

count
Int32 Int32 Int32 Int32

最多读取的字符数。The maximum number of characters to read. 如果在读取指定数目的字符到缓冲区之前,读取器就已达到末尾,那么该方法返回。If the end of the reader is reached before the specified number of characters is read into the buffer, the method returns.

返回

已读取的字符数。The number of characters that have been read. 该数会小于或等于 count,具体取决于读取器中是否有可用的数据。The number will be less than or equal to count, depending on whether the data is available within the reader. 如果调用此方法时没有更多的字符留下可供读取,则此方法返回 0(零)。This method returns 0 (zero) if it is called when no more characters are left to read.

异常

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

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

注解

此方法返回后count读取字符或到达文件末尾。This method returns after either count characters are read or the end of the file is reached. ReadBlock 是此方法条块化版本。is a blocking version of this method.

TextReader 类是抽象类。The TextReader class is an abstract class. 因此,您实例化它在代码中。Therefore, you do not instantiate it in your code. 有关使用的示例Read方法,请参阅StreamReader.Read方法。For an example of using the Read method, see the StreamReader.Read method.

另请参阅

适用于