I'm trying to understand the difference between the following two methods. Assume this is a middle/business layer functionality, is there any difference between these method signatures?

public Task<IList<EntityDocument>> GetEntityDocument(string id)
{
    return this.GetEntityDocuments(new[] { id});
}

public async Task<IList<EntityDocument>> GetEntityDocument(string id)
{
    return await this.GetEntityDocuments(new[] { id});
}

In the 2nd method signature I'm adding a async/await additionally. The result of this will be same. Everything will work perfectly when any of these methods are called from a async controller method or any other caller (where i will actually await this call). So does it really matter which one I am using?

For completeness adding the inner method call too (that actually does the network call and awaits.

public async Task<IList<EntityDocument>> GetEntityDocuments(string[] ids)
{
    // Prepare http client, headers etc
    // other non async code....

    // Do Some http call and return response
    return await this.messagingClient.PostAsync<string[], IList<EntityDocument>>(
        ids,
        requestHeader,
        null,
        queryParameters).ConfigureAwait(false);
}

0 Answers