共用方式為


StringWriter.WriteLineAsync 方法

定義

以非同步方式將資料寫入字串,後接行結束字元。

多載

WriteLineAsync(StringBuilder, CancellationToken)

以非同步方式將字串產生器的字串表示寫入目前字串,後接行結束字元。

WriteLineAsync(Char)

以非同步方式將字元寫入字串,後接行結束字元。

WriteLineAsync(String)

以非同步方式將字串寫入目前字串,後接行結束字元。

WriteLineAsync(ReadOnlyMemory<Char>, CancellationToken)

以非同步方式將字元的記憶體區域字串表示寫入目前字串,後接行結束字元。

WriteLineAsync(Char[], Int32, Int32)

以非同步方式將字元的子陣列寫入字串,後接行結束字元。

WriteLineAsync(StringBuilder, CancellationToken)

來源:
StringWriter.cs
來源:
StringWriter.cs
來源:
StringWriter.cs

以非同步方式將字串產生器的字串表示寫入目前字串,後接行結束字元。

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

參數

value
StringBuilder

要寫入字串的字串產生器。

cancellationToken
CancellationToken

用來監視是否有取消要求的語彙基元。 預設值是 None

傳回

表示非同步寫入作業的工作。

例外狀況

取消令牌已取消。 此例外狀況會儲存在傳回的工作中。

備註

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用狀況例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用狀況例外狀況,例如 ArgumentException,仍會同步擲回。 如需預存的例外狀況,請參閱 所 WriteLine(StringBuilder)擲回的例外狀況。

適用於

WriteLineAsync(Char)

來源:
StringWriter.cs
來源:
StringWriter.cs
來源:
StringWriter.cs

以非同步方式將字元寫入字串,後接行結束字元。

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

參數

value
Char

要寫入字串的字元。

傳回

表示非同步寫入作業的工作。

屬性

例外狀況

字串寫入器已經處置。

字串寫入器目前正由先前的寫入作業所使用。

範例

下列範例示範如何使用 方法來撰寫字元 WriteLineAsync(Char)

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.WriteLineAsync(c);
                }
                Console.WriteLine(stringToWrite.ToString());
            }
        }
    }
}
// The example displays the following output:
//
// Characters in StringBuilder
// a
// n
// d
//
// c
// h
// a
// r
// s
//
// t
// o
//
// a
// d
// d
//
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.WriteLineAsync(c)
            Next
            Console.WriteLine(stringToWrite.ToString())
        End Using
    End Sub
End Module
' The example displays the following output:
'
' Characters in StringBuilder
' a
' n
' d 
'
' c
' h
' a
' r
' s
' 
' t
' o
'
' a
' d
' d
'

備註

行終止符是由 屬性所 NewLine 定義。

適用於

WriteLineAsync(String)

來源:
StringWriter.cs
來源:
StringWriter.cs
來源:
StringWriter.cs

以非同步方式將字串寫入目前字串,後接行結束字元。

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

參數

value
String

要寫入的字串。 如果值為 null,則只會寫入行結束字元。

傳回

表示非同步寫入作業的工作。

屬性

例外狀況

字串寫入器已經處置。

字串寫入器目前正由先前的寫入作業所使用。

範例

下列範例示範如何使用 方法來撰寫字串 WriteLineAsync(String)

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.WriteLineAsync("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.WriteLineAsync("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
'

備註

行終止符是由 屬性所 NewLine 定義。

適用於

WriteLineAsync(ReadOnlyMemory<Char>, CancellationToken)

來源:
StringWriter.cs
來源:
StringWriter.cs
來源:
StringWriter.cs

以非同步方式將字元的記憶體區域字串表示寫入目前字串,後接行結束字元。

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

參數

buffer
ReadOnlyMemory<Char>

要寫入字串的字元記憶體區域。

cancellationToken
CancellationToken

用來監視是否有取消要求的語彙基元。 預設值是 None

傳回

表示非同步寫入作業的工作。

例外狀況

取消令牌已取消。 此例外狀況會儲存在傳回的工作中。

適用於

WriteLineAsync(Char[], Int32, Int32)

來源:
StringWriter.cs
來源:
StringWriter.cs
來源:
StringWriter.cs

以非同步方式將字元的子陣列寫入字串,後接行結束字元。

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

參數

buffer
Char[]

資料寫入來源的字元陣列。

index
Int32

緩衝區中要開始讀取資料的位置。

count
Int32

要寫入的最大字元數。

傳回

表示非同步寫入作業的工作。

屬性

例外狀況

buffernull

index 加上 count 大於緩衝區長度。

indexcount 為負。

字串寫入器已經處置。

字串寫入器目前正由先前的寫入作業所使用。

範例

下列範例示範如何使用 方法來撰寫字元 WriteLineAsync(Char[], Int32, Int32)

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.WriteLineAsync(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.WriteLineAsync(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
'

備註

行終止符是由 屬性所 NewLine 定義。

適用於