I came across this question on a test, and I'm stuck between two answers. Which would you consider correct and why? Is it possible that both are acceptable?
What have I read so far. Task is already asynchronous, so there would be no need to declare async again, A is correct. The return from A is not a string, but a Task, so B is correct. And I also saw a fiddle example showing that both of them work...
"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?"
Option A:
protected async void StartTask()
{
string result = await GetData();
...
}
public Task<string> GetData()
{
...
}
Option B:
protected async void StartTask()
{
string result = await GetData();
...
}
public async Task<string> GetData()
{
...
}