Share via


StreamReader.ReadLine Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Updated: December 2010

When it is called by trusted applications, reads a line of characters from the current stream and returns the data as a string.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overrides Function ReadLine As String
public override string ReadLine()

Return Value

Type: System.String
The next line from the input stream, or nulla null reference (Nothing in Visual Basic) if the end of the input stream is reached.

Exceptions

Exception Condition
OutOfMemoryException

There is insufficient memory to allocate a buffer for the returned string.

IOException

An I/O error occurs.

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 nulla null reference (Nothing in Visual Basic) if the end of the input stream is reached.

This method overrides ReadLine.

If the current method throws an OutOfMemoryException, the reader's position in the underlying Stream object is advanced by the number of characters the method was able to read, but the characters already read into the internal 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 DiscardBufferedData method; however, this method slows performance and should be called only when absolutely necessary.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Change History

Date

History

Reason

December 2010

Added information about calling DiscardBufferedData.

Information enhancement.