📜  async where linq - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:13.134000             🧑  作者: Mango

代码示例1
static async Task> Where(
    this IEnumerable source, Func> predicate)
{
    var results = new ConcurrentQueue();
    var tasks = source.Select(
        async x =>
        {
            if (await predicate(x))
                results.Enqueue(x);
        });
    await Task.WhenAll(tasks);
    return results;
}


var filteredAddresses = await addresses.Where(MeetsCriteria);