Which code segment should you use?

You are developing an application that uses multiple asynchronous tasks to optimize performance. The
application will be deployed in a distributed environment.
You need to retrieve the result of an asynchronous task that retrieves data from a web service.
The data will later be parsed by a separate task.
Which code segment should you use?

You are developing an application that uses multiple asynchronous tasks to optimize performance. The
application will be deployed in a distributed environment.
You need to retrieve the result of an asynchronous task that retrieves data from a web service.
The data will later be parsed by a separate task.
Which code segment should you use?

A.
Option A

B.
Option B

C.
Option C

D.
Option D



Leave a Reply 8

Your email address will not be published. Required fields are marked *


Oleg Mursalov

Oleg Mursalov

A

Chriss

Chriss

Should be B. A is an invalid casting.

Zz

Zz

A is correct. You need to put async only when you have await in the body of the method.

Denis

Denis

We don’t know does the body of GetData() contain await or not. So the the answer could be A or B and the question is not correct I guess.

didii

didii

Agree. Depends on how the return statement is formatted in GetData(). If it returns a Task object it’s A, if it returns a string it’s B.

The following are both correct:

public Task GetData() => Task.FromResult(“some data”);
and
public async Task GetData() => “some data”;

Pascal

Pascal

Asynchronous Task they said, You need to retrieve the result of an asynchronous task. so its B