TextReader.ReadAsync Methode
Definition
Überlädt
ReadAsync(Char[], Int32, Int32) |
Liest asynchron eine angegebene Höchstanzahl von Zeichen aus dem aktuellen Textreader und schreibt die Daten in einen Puffer, wobei am angegebenen Index begonnen wird.Reads a specified maximum number of characters from the current text reader asynchronously and writes the data to a buffer, beginning at the specified index. |
ReadAsync(Memory<Char>, CancellationToken) |
Liest die Zeichen asynchron aus dem aktuellen Datenstrom in einen Speicherblock.Asynchronously reads the characters from the current stream into a memory block. |
ReadAsync(Char[], Int32, Int32)
Liest asynchron eine angegebene Höchstanzahl von Zeichen aus dem aktuellen Textreader und schreibt die Daten in einen Puffer, wobei am angegebenen Index begonnen wird.Reads a specified maximum number of characters from the current text reader asynchronously and writes the data to a buffer, beginning at the specified index.
public:
virtual System::Threading::Tasks::Task<int> ^ ReadAsync(cli::array <char> ^ buffer, int index, int count);
public virtual System.Threading.Tasks.Task<int> ReadAsync (char[] buffer, int index, int count);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual System.Threading.Tasks.Task<int> ReadAsync (char[] buffer, int index, int count);
abstract member ReadAsync : char[] * int * int -> System.Threading.Tasks.Task<int>
override this.ReadAsync : char[] * int * int -> System.Threading.Tasks.Task<int>
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member ReadAsync : char[] * int * int -> System.Threading.Tasks.Task<int>
override this.ReadAsync : char[] * int * int -> System.Threading.Tasks.Task<int>
Public Overridable Function ReadAsync (buffer As Char(), index As Integer, count As Integer) As Task(Of Integer)
Parameter
- buffer
- Char[]
Enthält nach der Rückgabe dieser Methode das angegebene Zeichenarray mit den Werten zwischen index
und (index
+ count
- 1), die durch die aus der aktuellen Quelle gelesenen Zeichen ersetzt wurden.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
Die Position in buffer
, an der mit dem Schreiben begonnen wird.The position in buffer
at which to begin writing.
- count
- Int32
Die maximale Anzahl der zu lesenden Zeichen.The maximum number of characters to read. Wenn das Ende des Texts erreicht ist, bevor die angegebene Anzahl von Zeichen in den Puffer gelesen wurde, erfolgt die aktuelle Methodenrückgabe.If the end of the text is reached before the specified number of characters is read into the buffer, the current method returns.
Gibt zurück
Eine Aufgabe, die den asynchronen Lesevorgang darstellt.A task that represents the asynchronous read operation. Der Wert des TResult
-Parameters enthält die Gesamtzahl der Bytes, die in den Puffer gelesen werden.The value of the TResult
parameter contains the total number of bytes read into the buffer. Der Ergebniswert kann niedriger als die Anzahl der angeforderten Bytes sein, wenn die Anzahl an derzeit verfügbaren Bytes kleiner ist als die angeforderte Anzahl, oder sie kann 0 (null) sein, wenn das Textende erreicht ist.The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the text has been reached.
- Attribute
Ausnahmen
buffer
ist null
.buffer
is null
.
index
oder count
ist ein negativer Wert.index
or count
is negative.
Die Summe von index
und count
ist größer als die Pufferlänge.The sum of index
and count
is larger than the buffer length.
Der Textreader wurde freigegeben.The text reader has been disposed.
Der Reader wird zurzeit von einem vorherigen Lesevorgang verwendet.The reader is currently in use by a previous read operation.
Hinweise
Die Aufgabe wird abgeschlossen, nachdem entweder die Anzahl der durch den-Parameter angegebenen Zeichen count
gelesen oder das Ende der Datei erreicht wurde.The task completes after either the number of characters specified by the count
parameter are read or the end of the file is reached.
Die TextReader-Klasse ist eine abstrakte Klasse.The TextReader class is an abstract class. Daher wird Sie nicht im Code instanziiert.Therefore, you do not instantiate it in your code. Ein Beispiel für die Verwendung der- ReadAsync Methode finden Sie unter der- StreamReader.ReadAsync Methode.For an example of using the ReadAsync method, see the StreamReader.ReadAsync method.
Siehe auch
- ReadAsync(Char[], Int32, Int32)
- ReadAsync(Char[], Int32, Int32)
- Datei- und Stream-E/AFile and Stream I/O
- Vorgehensweise: Lesen von Text aus einer DateiHow to: Read Text from a File
- Vorgehensweise: Schreiben von Text in eine DateiHow to: Write Text to a File
Gilt für:
ReadAsync(Memory<Char>, CancellationToken)
Liest die Zeichen asynchron aus dem aktuellen Datenstrom in einen Speicherblock.Asynchronously reads the characters from the current stream into a memory block.
public virtual System.Threading.Tasks.ValueTask<int> ReadAsync (Memory<char> buffer, System.Threading.CancellationToken cancellationToken = default);
abstract member ReadAsync : Memory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>
override this.ReadAsync : Memory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>
Public Overridable Function ReadAsync (buffer As Memory(Of Char), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Integer)
Parameter
Enthält nach dem Beenden dieser Methode den angegebene Speicherblock, der durch die aus der aktuellen Quelle gelesenen Zeichen ersetzt wurdeWhen this method returns, contains the specified memory block of characters replaced by the characters read from the current source.
- cancellationToken
- CancellationToken
Das Token zum Überwachen von Abbruchanforderungen.The token to monitor for cancellation requests. Der Standardwert ist None.The default value is None.
Gibt zurück
Ein Werttask, der den asynchronen Lesevorgang darstelltA value task that represents the asynchronous read operation. Der Wert des Typparameters enthält die Anzahl der gelesenen Zeichen bzw. 0 (null), wenn das Ende des Datenstroms erreicht ist und keine Daten gelesen wurden.The value of the type parameter contains the number of characters that have been read, or 0 if at the end of the stream and no data was read. Die Anzahl ist kleiner oder gleich der buffer
-Länge, abhängig davon, ob die Daten im Datenstrom verfügbar sind.The number will be less than or equal to the buffer
length, depending on whether the data is available within the stream.