© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
SWEETPONY

✅ How should I use SelectAsync?

I have this:
static public async Task<IEnumerable<TResult>> SelectAsync<TSource, TResult>(
    this IEnumerable<TSource> @this,                                         
    Func<TSource, Task<TResult>> selector) =>                                
    await Task.WhenAll(@this.Select(async x => await selector(x)             
            .ConfigureAwait(continueOnCapturedContext: false)))              
        .ConfigureAwait(continueOnCapturedContext: false); 
static public async Task<IEnumerable<TResult>> SelectAsync<TSource, TResult>(
    this IEnumerable<TSource> @this,                                         
    Func<TSource, Task<TResult>> selector) =>                                
    await Task.WhenAll(@this.Select(async x => await selector(x)             
            .ConfigureAwait(continueOnCapturedContext: false)))              
        .ConfigureAwait(continueOnCapturedContext: false); 


What is better way to call SelectAsync:
1.
public Task<List<ReportDefinitionDto>> ToDtos(        
    IEnumerable<ReportDefinitionModel> models,        
    CultureInfo culture) =>                           
    models.SelectAsync(model => ToDto(model, culture))
        .ToList();    
1.
public Task<List<ReportDefinitionDto>> ToDtos(        
    IEnumerable<ReportDefinitionModel> models,        
    CultureInfo culture) =>                           
    models.SelectAsync(model => ToDto(model, culture))
        .ToList();    

2.
public Task<List<ReportDefinitionDto>> ToDtos(        
    IEnumerable<ReportDefinitionModel> models,        
    CultureInfo culture) =>                           
    models.SelectAsync(async model => await ToDto(model, culture))
        .ToList();    
2.
public Task<List<ReportDefinitionDto>> ToDtos(        
    IEnumerable<ReportDefinitionModel> models,        
    CultureInfo culture) =>                           
    models.SelectAsync(async model => await ToDto(model, culture))
        .ToList();    
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Which Technologies should I use?
C#CC# / help
3y ago
What control should I use?
C#CC# / help
3y ago
✅ When and how should I use the Windows EventLog?
C#CC# / help
3y ago