StringWriter.WriteLineAsync Method (System.IO) (original) (raw)

Source:

StringWriter.cs

Source:

StringWriter.cs

Source:

StringWriter.cs

Source:

StringWriter.cs

asynchronously writes a subarray of characters to the string, followed by a line terminator.

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

Parameters

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.

Returns

A task that represents the asynchronous write operation.

Attributes

Exceptions

The index plus count is greater than the buffer length.

index or count is negative.

The string writer is disposed.

The string writer is currently in use by a previous write operation.

Examples

The following example shows how to write characters by using the WriteLineAsync(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.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
'

Remarks

The line terminator is defined by the NewLine property.

Applies to