Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​IO.​StreamReader
Assembly: System.Runtime
Inheritance: object → MarshalByRefObject → TextReader → StreamReader
Implements a <see cref="T:System.IO.TextReader" /> that reads characters from a byte stream in a particular encoding.
Fields and Constants
public static readonly
StreamReader
Null
A <see cref="T:System.IO.StreamReader" /> object around an empty stream.
Properties
public
Stream
BaseStream
Returns the underlying stream.
CurrentEncoding
Gets the current character encoding that the current <see cref="T:System.IO.StreamReader" /> object is using.
public
bool
EndOfStream
Gets a value that indicates whether the current stream position is at the end of the stream.
Methods
public
void
Close​()
Closes the <see cref="T:System.IO.StreamReader" /> object and the underlying stream, and releases any system resources associated with the reader.
public
void
DiscardBufferedData​()
Clears the internal buffer.
protected
void
Dispose​(bool disposing)
disposing
<see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
Closes the underlying stream, releases the unmanaged resources used by the <see cref="T:System.IO.StreamReader" /> , and optionally releases the managed resources.
public
int
Peek​() Returns An integer representing the next character to be read, or -1 if there are no characters to be read or if the stream does not support seeking.
Returns the next available character but does not consume it.
public
int
Read​() Returns The next character from the input stream represented as an <see cref="T:System.Int32" /> object, or -1 if no more characters are available.
Reads the next character from the input stream and advances the character position by one character.
public
int
Read​(char[] buffer,
int index,
int count)
buffer
When this method returns, contains the specified character array with the values between <paramref name="index" /> and ( <c>index + count - 1</c> ) replaced by the characters read from the current source.
index
The index of <paramref name="buffer" /> at which to begin writing.
count
The maximum number of characters to read.
Returns The number of characters that have been read, or 0 if at the end of the stream and no data was read. The number will be less than or equal to the <paramref name="count" /> parameter, depending on whether the data is available within the stream.
Reads a specified maximum of characters from the current stream into a buffer, beginning at the specified index.
ReadAsync​(char[] buffer,
int index,
int count)
buffer
When this method returns, contains the specified character array with the values between <paramref name="index" /> and ( <paramref name="index" /> + <paramref name="count" /> - 1) replaced by the characters read from the current source.
index
The position in <paramref name="buffer" /> at which to begin writing.
count
The maximum number of characters to read. If the end of the stream is reached before the specified number of characters is written into the buffer, the current method returns.
Returns A task that represents the asynchronous read operation. The value of the <paramref name="TResult" /> parameter contains the total number of characters read into the buffer. The result value can be less than the number of characters requested if the number of characters currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.
Reads a specified maximum number of characters from the current stream asynchronously and writes the data to a buffer, beginning at the specified index.
public
int
ReadBlock​(char[] buffer,
int index,
int count)
buffer
When this method returns, contains the specified character array with the values between <paramref name="index" /> and ( <c>index + count - 1</c> ) replaced by the characters read from the current source.
index
The position in <paramref name="buffer" /> at which to begin writing.
count
The maximum number of characters to read.
Returns The number of characters that have been read. The number will be less than or equal to <paramref name="count" /> , depending on whether all input characters have been read.
Reads a specified maximum number of characters from the current stream and writes the data to a buffer, beginning at the specified index.
ReadBlockAsync​(char[] buffer,
int index,
int count)
buffer
When this method returns, contains the specified character array with the values between <paramref name="index" /> and ( <paramref name="index" /> + <paramref name="count" /> - 1) replaced by the characters read from the current source.
index
The position in <paramref name="buffer" /> at which to begin writing.
count
The maximum number of characters to read. If the end of the stream is reached before the specified number of characters is written into the buffer, the method returns.
Returns A task that represents the asynchronous read operation. The value of the <paramref name="TResult" /> parameter contains the total number of characters read into the buffer. The result value can be less than the number of characters requested if the number of characters currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.
Reads a specified maximum number of characters from the current stream asynchronously and writes the data to a buffer, beginning at the specified index.
ReadBlockAsync​(Memory`1 buffer,
Threading.CancellationToken cancellationToken = null)
public
string
ReadLine​() Returns The next line from the input stream, or <see langword="null" /> if the end of the input stream is reached.
Reads a line of characters from the current stream and returns the data as a string.
ReadLineAsync​()
Returns A task that represents the asynchronous read operation. The value of the <paramref name="TResult" /> parameter contains the next line from the stream, or is <see langword="null" /> if all the characters have been read.
Reads a line of characters asynchronously from the current stream and returns the data as a string.
ReadLineAsync​(Threading.CancellationToken cancellationToken)
cancellationToken
The token to monitor for cancellation requests.
Returns A value task that represents the asynchronous read operation. The value of the <c>TResult</c> parameter contains the next line from the stream, or is <see langword="null" /> if all of the characters have been read.
Reads a line of characters asynchronously from the current stream and returns the data as a string.
public
string
ReadToEnd​() Returns The rest of the stream as a string, from the current position to the end. If the current position is at the end of the stream, returns an empty string ("").
Reads all characters from the current position to the end of the stream.
ReadToEndAsync​()
Returns A task that represents the asynchronous read operation. The value of the <paramref name="TResult" /> parameter contains a string with the characters from the current position to the end of the stream.
Reads all characters from the current position to the end of the stream asynchronously and returns them as one string.
ReadToEndAsync​(Threading.CancellationToken cancellationToken)
cancellationToken
The token to monitor for cancellation requests.
Returns A task that represents the asynchronous read operation. The value of the <c>TResult</c> parameter contains a string with the characters from the current position to the end of the stream.
Reads all characters from the current position to the end of the stream asynchronously and returns them as one string.
Releases all resources used by the <see cref="T:System.IO.TextReader" /> object.
public
object
GetLifetimeService​()
Inherited from MarshalByRefObject
Returns An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease" /> used to control the lifetime policy for this instance.
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
public
object
InitializeLifetimeService​()
Inherited from MarshalByRefObject
Returns An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease" /> used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the <see cref="P:System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseManagerPollTime" /> property.
Obtains a lifetime service object to control the lifetime policy for this instance.
protected
MarshalByRefObject
MemberwiseClone​(bool cloneIdentity)
Inherited from MarshalByRefObject
cloneIdentity
<see langword="false" /> to delete the current <see cref="T:System.MarshalByRefObject" /> object's identity, which will cause the object to be assigned a new identity when it is marshaled across a remoting boundary. A value of <see langword="false" /> is usually appropriate. <see langword="true" /> to copy the current <see cref="T:System.MarshalByRefObject" /> object's identity to its clone, which will cause remoting client calls to be routed to the remote server object.
Returns A shallow copy of the current <see cref="T:System.MarshalByRefObject" /> object.
Creates a shallow copy of the current <see cref="T:System.MarshalByRefObject" /> object.
public
bool
Equals​(object obj)
Inherited from object
obj
The object to compare with the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
Determines whether the specified object is equal to the current object.
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
int
GetHashCode​()
Inherited from object
Returns A hash code for the current object.
Serves as the default hash function.
public
Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates a shallow copy of the current <see cref="T:System.Object" /> .
public
string
ToString​()
Inherited from object
Returns A string that represents the current object.
Returns a string that represents the current object.