System.IO.StreamReader.ReadLine Method

Reads a line of characters from the current stream and returns the data as a string.

Syntax

public override string ReadLine ()

Returns

The next line from the input stream, or null if the end of the input stream is reached.

Exceptions

TypeReason
System.IO.IOExceptionAn I/O error occurred.
OutOfMemoryExceptionThere is insufficient memory to allocate a buffer for the returned string.

Remarks

A line is defined as a sequence of characters followed by a line feed ("\n"), a carriage return ("\r"), or a carriage return immediately followed by a line feed ("\r\n"). The string that is returned does not contain the terminating carriage return or line feed. The returned value is null if the end of the input stream is reached.

This method overrides TextReader.ReadLine.

If the current method throws an OutOfMemoryException, the reader's position in the underlying System.IO.Stream object is advanced by the number of characters the method was able to read, but the characters already read into the internal StreamReader.ReadLine buffer are discarded. If you manipulate the position of the underlying stream after reading data into the buffer, the position of the underlying stream might not match the position of the internal buffer. To reset the internal buffer, call the StreamReader.DiscardBufferedData method; however, this method slows performance and should be called only when absolutely necessary.

For a list of common I/O tasks, see Common I/O Tasks.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0