StringReader.ReadLineAsync メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
現在の文字列から非同期的に文字の行を読み取り、データを文字列として返します。
public:
override System::Threading::Tasks::Task<System::String ^> ^ ReadLineAsync();
public override System.Threading.Tasks.Task<string> ReadLineAsync();
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task<string> ReadLineAsync();
override this.ReadLineAsync : unit -> System.Threading.Tasks.Task<string>
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.ReadLineAsync : unit -> System.Threading.Tasks.Task<string>
Public Overrides Function ReadLineAsync () As Task(Of String)
返品
非同期読み取り操作を表すタスク。
TResult パラメーターの値には、文字列リーダーの次の行が含まれています。または、すべての文字が読み取られた場合はnull。
- 属性
例外
次の行の文字数が Int32.MaxValue を超えています。
文字列リーダーが破棄されました。
リーダーは現在、以前の読み取り操作で使用されています。
例
次の例は、文字列から 1 行ずつ非同期的に読み取る方法を示しています。
using System;
using System.IO;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
ReadCharacters();
}
static async void ReadCharacters()
{
StringBuilder stringToRead = new StringBuilder();
stringToRead.AppendLine("Characters in 1st line to read");
stringToRead.AppendLine("and 2nd line");
stringToRead.AppendLine("and the end");
string readText;
using (StringReader reader = new StringReader(stringToRead.ToString()))
{
while ((readText = await reader.ReadLineAsync()) != null)
{
Console.WriteLine(readText);
}
}
}
}
}
// The example displays the following output:
//
// Characters in 1st line to read
// and 2nd line
// and the end
//
Imports System.IO
Imports System.Text
Module Module1
Sub Main()
ReadCharacters()
End Sub
Async Sub ReadCharacters()
Dim stringToRead = New StringBuilder()
stringToRead.AppendLine("Characters in 1st line to read")
stringToRead.AppendLine("and 2nd line")
stringToRead.AppendLine("and the end")
Using reader As StringReader = New StringReader(stringToRead.ToString())
Dim readText As String = Await reader.ReadLineAsync()
While Not IsNothing(readText)
Console.WriteLine(readText)
readText = Await reader.ReadLineAsync()
End While
End Using
End Sub
End Module
' The example displays the following output:
'
' Characters in 1st line to read
' and 2nd line
' and the end
'
注釈
このメソッドは、メソッドの同期的な例外がスローできるすべての非使用例外を返すタスクに格納します。 返されたタスクに例外が格納されている場合、その例外はタスクが待機しているときにスローされます。 ArgumentException などの使用に関する例外は、引き続き同期的にスローされます。 格納されている例外については、 ReadLine()によってスローされる例外を参照してください。