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?
A. Option A
B. Option B
C. Option C
D. Option D
2 Comments on “Which code segment should you use?”
raosays:
C
0
1
ivannathansays:
“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();}
C
0
1
“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