DownloadDataCompletedEventArgs.Result 屬性

定義

取得 DownloadDataAsync 方法所下載的資料。

C#
public byte[] Result { get; }

屬性值

Byte[]

Byte 陣列,包含下載的資料。

範例

下列程式代碼範例會顯示此屬性的值。

C#
private static void DownloadDataCallback(Object sender, DownloadDataCompletedEventArgs e)
{
    System.Threading.AutoResetEvent waiter = (System.Threading.AutoResetEvent)e.UserState;

    try
    {
        // If the request was not canceled and did not throw
        // an exception, display the resource.
        if (!e.Cancelled && e.Error == null)
        {
            byte[] data = (byte[])e.Result;
            string textData = System.Text.Encoding.UTF8.GetString(data);

            Console.WriteLine(textData);
        }
    }
    finally
    {
        // Let the main application thread resume.
        waiter.Set();
    }
}

備註

您應該先檢查 和 Cancelled 屬性,Error再使用這個屬性所傳回的數據。 Error如果屬性的值是Exception物件,或Cancelled屬性的值是 true,異步操作未正確完成,而且Result屬性值無效。

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1