0

How to use yield return when method's return-type is a Task, for example Task<IEnumerable<string>>?

This is my code:

    private async Task<IEnumerable<string>> GetNameAsync(List<MyEntity> entities)
    {
        List<string> finalstrings = new List<string>();

        foreach (var item in entities)
        {
            finalstrings.Add(item.Name);
        }

        return finalstrings;
    }

I'm using dotnet core 3.1.

Thanks in advance.

Peter B
  • 22,460
  • 5
  • 32
  • 69
Mehrdad
  • 1,523
  • 9
  • 23

0 Answers0