PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are developing an application that uses multiple asynchronous tasks to optimize performance.
You need to retrieve the result of an asynchronous task.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
Option A

B.
Option B

C.
Option C

D.
Option D

2 Comments on “Which code segment should you use?

  1. ivannathan says:

    “A” option works fine:

    public Task GetData() {return new Task(()=>”asd”);}
    protected async void StartTask() {string result = await GetData();}

    “C” option also can work, but it requires additional await in GetData, which is really useless :
    public async Task GetData() {return await new Task}
    public async void StartTask() {string result = await GetData();}

    So I think the correct answer is “A”




    1



    0

Leave a Reply