StringWriter.WriteAsync メソッド

定義

文字列にデータを非同期で書き込みます。Writes data to the string asynchronously.

オーバーロード

WriteAsync(Char)

文字を非同期で文字列に書き込みます。Writes a character to the string asynchronously.

WriteAsync(String)

現在の文字列に文字列を非同期的に書き込みます。Writes a string to the current string asynchronously.

WriteAsync(ReadOnlyMemory<Char>, CancellationToken)

文字のメモリ領域を文字列に非同期で書き込みます。Asynchronously writes a memory region of characters to the string.

WriteAsync(StringBuilder, CancellationToken)

文字列ビルダーのテキスト表現を文字列に非同期で書き込みます。Asynchronously writes the text representation of a string builder to the string.

WriteAsync(Char[], Int32, Int32)

文字の部分配列を文字列に非同期で書き込みます。Writes a subarray of characters to the string asynchronously.

WriteAsync(Char)

文字を非同期で文字列に書き込みます。Writes a character to the string asynchronously.

public:
 override System::Threading::Tasks::Task ^ WriteAsync(char value);
public override System.Threading.Tasks.Task WriteAsync (char value);
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task WriteAsync (char value);
override this.WriteAsync : char -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.WriteAsync : char -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (value As Char) As Task

パラメーター

value
Char

文字列に書き込む文字。The character to write to the string.

戻り値

Task

非同期の書き込み操作を表すタスク。A task that represents the asynchronous write operation.

属性

例外

文字列ライターが破棄されています。The string writer is disposed.

文字列ライターは現在、前の書き込み操作で使用中です。The string writer is currently in use by a previous write operation.

次の例は、メソッドを使用して文字を書き込む方法を示して WriteAsync(Char) います。The following example shows how to write characters by using the WriteAsync(Char) method.

using System;
using System.Text;
using System.IO;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            WriteCharacters();
        }

        static async void WriteCharacters()
        {
            StringBuilder stringToWrite = new StringBuilder("Characters in StringBuilder");
            stringToWrite.AppendLine();

            using (StringWriter writer = new StringWriter(stringToWrite))
            {
                UnicodeEncoding ue = new UnicodeEncoding();
                char[] charsToAdd = ue.GetChars(ue.GetBytes("and chars to add"));
                foreach (char c in charsToAdd)
                {
                    await writer.WriteAsync(c);
                }
                Console.WriteLine(stringToWrite.ToString());
            }
        }
    }
}
// The example displays the following output:
//
// Characters in StringBuilder
// and chars to add
//
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        WriteCharacters()
    End Sub

    Async Sub WriteCharacters()
        Dim stringToWrite As StringBuilder = New StringBuilder("Characters in StringBuilder")
        stringToWrite.AppendLine()

        Using writer As StringWriter = New StringWriter(stringToWrite)

            Dim ue As UnicodeEncoding = New UnicodeEncoding()
            Dim charsToAdd() = ue.GetChars(ue.GetBytes("and chars to add"))
            For Each c As Char In charsToAdd
                Await writer.WriteAsync(c)
            Next
            Console.WriteLine(stringToWrite.ToString())
        End Using
    End Sub
End Module
' The example displays the following output:
'
' Characters in StringBuilder
' and chars to add
'

適用対象

WriteAsync(String)

現在の文字列に文字列を非同期的に書き込みます。Writes a string to the current string asynchronously.

public:
 override System::Threading::Tasks::Task ^ WriteAsync(System::String ^ value);
public override System.Threading.Tasks.Task WriteAsync (string value);
public override System.Threading.Tasks.Task WriteAsync (string? value);
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task WriteAsync (string value);
override this.WriteAsync : string -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.WriteAsync : string -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (value As String) As Task

パラメーター

value
String

書き込む文字列。The string to write. valuenull の場合は、何もテキスト ストリームに書き込みません。If value is null, nothing is written to the text stream.

戻り値

Task

非同期の書き込み操作を表すタスク。A task that represents the asynchronous write operation.

属性

例外

文字列ライターが破棄されています。The string writer is disposed.

文字列ライターは現在、前の書き込み操作で使用中です。The string writer is currently in use by a previous write operation.

次の例は、メソッドを使用して文字列を書き込む方法を示して WriteAsync(String) います。The following example shows how to write a string by using the WriteAsync(String) method.

using System;
using System.Text;
using System.IO;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            WriteCharacters();
        }

        static async void WriteCharacters()
        {
            StringBuilder stringToWrite = new StringBuilder("Characters in StringBuilder");
            stringToWrite.AppendLine();

            using (StringWriter writer = new StringWriter(stringToWrite))
            {
                await writer.WriteAsync("and add characters through StringWriter");
                Console.WriteLine(stringToWrite.ToString());
            }
        }
    }
}
// The example displays the following output:
//
// Characters in StringBuilder
// and add characters through StringWriter
//
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        WriteCharacters()
    End Sub

    Async Sub WriteCharacters()
        Dim stringToWrite As StringBuilder = New StringBuilder("Characters in StringBuilder")
        stringToWrite.AppendLine()

        Using writer As StringWriter = New StringWriter(stringToWrite)
            Await writer.WriteAsync("and add characters through StringWriter")
            Console.WriteLine(stringToWrite.ToString())
        End Using
    End Sub
End Module
' The example displays the following output:
'
' Characters in StringBuilder
' and add characters through StringWriter
'

適用対象

WriteAsync(ReadOnlyMemory<Char>, CancellationToken)

文字のメモリ領域を文字列に非同期で書き込みます。Asynchronously writes a memory region of characters to the string.

public override System.Threading.Tasks.Task? WriteAsync (ReadOnlyMemory<char> buffer, System.Threading.CancellationToken cancellationToken = default);
public override System.Threading.Tasks.Task WriteAsync (ReadOnlyMemory<char> buffer, System.Threading.CancellationToken cancellationToken = default);
override this.WriteAsync : ReadOnlyMemory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (buffer As ReadOnlyMemory(Of Char), Optional cancellationToken As CancellationToken = Nothing) As Task

パラメーター

buffer
ReadOnlyMemory<Char>

文字列に書き込む文字メモリ領域。The character memory region to write to the string.

cancellationToken
CancellationToken

キャンセル要求を監視するためのトークン。The token to monitor for cancellation requests. 既定値は None です。The default value is None.

戻り値

Task

非同期の書き込み操作を表すタスク。A task that represents the asynchronous write operation.

適用対象

WriteAsync(StringBuilder, CancellationToken)

文字列ビルダーのテキスト表現を文字列に非同期で書き込みます。Asynchronously writes the text representation of a string builder to the string.

public override System.Threading.Tasks.Task WriteAsync (System.Text.StringBuilder? value, System.Threading.CancellationToken cancellationToken = default);
override this.WriteAsync : System.Text.StringBuilder * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (value As StringBuilder, Optional cancellationToken As CancellationToken = Nothing) As Task

パラメーター

value
StringBuilder

文字列に書き込む文字列ビルダー。The string builder to write to the string.

cancellationToken
CancellationToken

キャンセル要求を監視するためのトークン。The token to monitor for cancellation requests. 既定値は None です。The default value is None.

戻り値

Task

非同期の書き込み操作を表すタスク。A task that represents the asynchronous write operation.

適用対象

WriteAsync(Char[], Int32, Int32)

文字の部分配列を文字列に非同期で書き込みます。Writes a subarray of characters to the string asynchronously.

public:
 override System::Threading::Tasks::Task ^ WriteAsync(cli::array <char> ^ buffer, int index, int count);
public override System.Threading.Tasks.Task WriteAsync (char[] buffer, int index, int count);
[System.Runtime.InteropServices.ComVisible(false)]
public override System.Threading.Tasks.Task WriteAsync (char[] buffer, int index, int count);
override this.WriteAsync : char[] * int * int -> System.Threading.Tasks.Task
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.WriteAsync : char[] * int * int -> System.Threading.Tasks.Task
Public Overrides Function WriteAsync (buffer As Char(), index As Integer, count As Integer) As Task

パラメーター

buffer
Char[]

データの書き込み元の文字配列。The character array to write data from.

index
Int32

データの読み取りを開始する、バッファー内の位置。The position in the buffer at which to start reading data.

count
Int32

書き込む文字の最大数。The maximum number of characters to write.

戻り値

Task

非同期の書き込み操作を表すタスク。A task that represents the asynchronous write operation.

属性

例外

buffernullです。buffer is null.

indexcount を加算した値がバッファーの長さを超えています。The index plus count is greater than the buffer length.

index または count が負の値です。index or count is negative.

文字列ライターが破棄されています。The string writer is disposed.

文字列ライターは現在、前の書き込み操作で使用中です。The string writer is currently in use by a previous write operation.

次の例は、メソッドを使用して文字を書き込む方法を示して WriteAsync(Char[], Int32, Int32) います。The following example shows how to write characters by using the WriteAsync(Char[], Int32, Int32) method.

using System;
using System.Text;
using System.IO;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            WriteCharacters();
        }

        static async void WriteCharacters()
        {
            StringBuilder stringToWrite = new StringBuilder("Characters in StringBuilder");
            stringToWrite.AppendLine();

            using (StringWriter writer = new StringWriter(stringToWrite))
            {
                UnicodeEncoding ue = new UnicodeEncoding();
                char[] charsToAdd = ue.GetChars(ue.GetBytes("and chars to add"));

                await writer.WriteAsync(charsToAdd, 0, charsToAdd.Length);

                Console.WriteLine(stringToWrite.ToString());
            }
        }
    }
}
// The example displays the following output:
//
// Characters in StringBuilder
// and chars to add
//
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        WriteCharacters()
    End Sub

    Async Sub WriteCharacters()
        Dim stringToWrite As StringBuilder = New StringBuilder("Characters in StringBuilder")
        stringToWrite.AppendLine()

        Using writer As StringWriter = New StringWriter(stringToWrite)

            Dim ue As UnicodeEncoding = New UnicodeEncoding()
            Dim charsToAdd() = ue.GetChars(ue.GetBytes("and chars to add"))

            Await writer.WriteAsync(charsToAdd, 0, charsToAdd.Length)

            Console.WriteLine(stringToWrite.ToString())
        End Using
    End Sub
End Module
' The example displays the following output:
'
' Characters in StringBuilder
' and chars to add
'

適用対象