DownloadStringCompletedEventArgs.Result 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 DownloadStringAsync 方法所下載的資料。
public:
property System::String ^ Result { System::String ^ get(); };
public string Result { get; }
member this.Result : string
Public ReadOnly Property Result As String
屬性值
String,包含下載的資料。
範例
下列程式代碼範例會顯示這個屬性的值。
void DownloadStringCallback2( Object^ /*sender*/, DownloadStringCompletedEventArgs^ e )
{
// If the request was not canceled and did not throw
// an exception, display the resource.
if ( !e->Cancelled && e->Error == nullptr )
{
String^ textString = dynamic_cast<String^>(e->Result);
Console::WriteLine( textString );
}
}
private static void DownloadStringCallback2(Object sender, DownloadStringCompletedEventArgs e)
{
// If the request was not canceled and did not throw
// an exception, display the resource.
if (!e.Cancelled && e.Error == null)
{
string textString = (string)e.Result;
Console.WriteLine(textString);
}
}
Private Shared Sub DownloadStringCallback2(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)
' If the request was not canceled and did not throw
' an exception, display the resource.
If e.Cancelled = False AndAlso e.Error Is Nothing Then
Dim textString As String = CStr(e.Result)
Console.WriteLine(textString)
End If
End Sub
備註
您應該先檢查 和 Cancelled 屬性,Error再使用此屬性所傳回的數據。
Error如果屬性值為 Exception 物件,或Cancelled屬性值為 true
,則異步操作未正確完成,且Result屬性值無效。