728x90
시퀀스에 누적함수를 적용할때 사용됩니다.
namespace ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
string[] fruits = { "apple", "mango", "orange", "passionfruit", "grape" };
// 문자열연결
var data = fruits.Aggregate((str1, str2) => str1 + ", " + str2);
Console.WriteLine(data);
// 가장 긴 문자열 찾기
string longestName = fruits.Aggregate((longest, next) =>
next.Length > longest.Length ? next : longest);
Console.WriteLine("The fruit with the longest name is {0}.", longestName);
Console.Read();
}
}
}
결과

참고
https://learn.microsoft.com/ko-kr/dotnet/api/system.linq.enumerable.aggregate?view=net-7.0
Enumerable.Aggregate 메서드 (System.Linq)
시퀀스에 누적기 함수를 적용합니다. 지정된 시드 값은 초기 누적기 값으로 사용되고 지정된 함수는 결과 값을 선택하는 데 사용됩니다.
learn.microsoft.com
728x90
'C#' 카테고리의 다른 글
[C#] Mediatr 참고 링크 (0) | 2023.11.08 |
---|---|
[C#] Indexer (0) | 2023.10.17 |
[C#] Liquid Template 사용하기 - Fluid (0) | 2023.09.21 |
[C#/Oracle] Oracle Parameter 순서 (0) | 2023.09.19 |
[C#] 사용자 다운로드 경로 및 환경변수 값 알아내기 (0) | 2023.09.17 |