这两个代码块之间有区别吗?

时间:2019-06-20 13:00:46

标签: c# xamarin

我已经测试了两个代码块,并且都返回相同的结果,TitleNewsTitle和TitleNewsBody在两种情况下都具有相同的字符串。

两个代码块之间有什么区别?我使用哪个代码块有关系吗?

代码块1:

    ReadTitleNews1();

    private void ReadTitleNews1()
    {
        var request = new GetTitleNewsRequest { };
        var loginTask = PlayFabClientAPI.GetTitleNewsAsync(request);
        loginTask.ContinueWith(OnReadTitleNewsComplete);
    }

    private void OnReadTitleNewsComplete(Task<PlayFabResult<GetTitleNewsResult>> task)
    {
        var newLabel = "Unknown failure";
        if (task.Result.Result != null)
        {
            newLabel = "Got title messages!";
            TitleNewsTitle = task.Result.Result.News[0].Title;
            TitleNewsBody = task.Result.Result.News[0].Body;
        }
        if (task.Result.Error != null)
        {
            newLabel = "Something went wrong.\n"
                + "Here's some debug information:\n"
                + task.Result.Error.GenerateErrorReport();
        }
        lock (_myLabelText)
        {
            _myLabelText = newLabel;
        }
    }

代码块2:

    ReadTitleNews2();

    public async void ReadTitleNews2()
    {
        await GetTitleNews();
    }

    private async Task GetTitleNews()
    {
        var result = await PlayFabClientAPI.GetTitleNewsAsync(new GetTitleNewsRequest());

        if (result.Error != null)
        {
            // Handle error if any
            Console.WriteLine(result.Error.GenerateErrorReport());
        }
        else
        {
            Console.WriteLine("Got title messages!");
            TitleNewsTitle = result.Result.News[0].Title;
            TitleNewsBody = result.Result.News[0].Body;
        }
    }

https://api.playfab.com/documentation/client/method/GetTitleNews

0 个答案:

没有答案