[C#/LINQ/.NET5] AsyncEnumerable 클래스 : CountAsync 확장 메소드를 사용해 비동기 열거 가능 시퀀스에서 조건을 충족하는 요소 수 구하기
C#/Linq 2021. 8. 15. 01:14728x90
728x170
▶ Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 값 열거 가능형 구하기 (비동기) - GetValueEnumerableAsync()
/// <summary>
/// 값 열거 가능형 구하기 (비동기)
/// </summary>
/// <returns>값 열거 가능형</returns>
private static async IAsyncEnumerable<int> GetValueEnumerableAsync()
{
for(int i = 0; i < 10; i++)
{
await Task.Delay(i * 100);
yield return i;
}
}
#endregion
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
/// <returns>태스크</returns>
private static async Task Main()
{
int count = await GetValueEnumerableAsync().CountAsync(value => value % 2 == 0);
Console.WriteLine(count);
}
#endregion
}
}
728x90
그리드형(광고전용)