A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://learn.microsoft.com/en-us/dotnet/api/system.io.streamwriter.writeasync below:

StreamWriter.WriteAsync Method (System.IO) | Microsoft Learn

Source:
StreamWriter.cs
Source:
StreamWriter.cs
Source:
StreamWriter.cs
Source:
StreamWriter.cs

Asynchronously writes a subarray of characters to the stream.

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
Parameters
buffer
Char[]

A character array that contains the data to write.

index
Int32

The character position in the buffer at which to begin 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 stream writer is disposed.

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

Examples

The following example shows how to write multiple characters to a text file by using the WriteAsync(Char[], Int32, Int32) method.

using System.IO;
using System.Text;

namespace ConsoleApplication
{
    class Program5
    {
        static void Main()
        {
            WriteCharacters();
        }

        static async void WriteCharacters()
        {
            UnicodeEncoding ue = new UnicodeEncoding();
            char[] charsToAdd = ue.GetChars(ue.GetBytes("Example string"));
            using (StreamWriter writer = File.CreateText("newfile.txt"))
            {
                await writer.WriteAsync(charsToAdd, 0, charsToAdd.Length);
            }
        }
    }
}
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        WriteCharacters()
    End Sub

    Async Sub WriteCharacters()
        Dim ue As UnicodeEncoding = New UnicodeEncoding()
        Dim charsToAdd() = ue.GetChars(ue.GetBytes("Example string"))

        Using writer As StreamWriter = File.CreateText("newfile.txt")
            Await writer.WriteAsync(charsToAdd, 0, charsToAdd.Length)
        End Using
    End Sub
End Module
Remarks

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Write(Char[], Int32, Int32).


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4