Aggregate() 메서드는 시퀀스에 누산기 함수를 적용합니다.
다음은 우리의 배열입니다 -
string[] arr = { "DemoOne", "DemoTwo", "DemoThree", "DemoFour"}; 이제 Aggregate() 메서드를 사용합니다. 비교를 위해 ssed 값을 "DemoFive"로 설정했습니다.
string res = arr.AsQueryable().Aggregate("DemoFive", (longest, next) => next.Length > longest.Length ? next : longest,str => str.ToLower()); 여기서 결과 문자열은 초기 시드 값(예:"DemoFive")보다 더 많은 문자를 가져야 합니다.
예
using System;
using System.Linq;
class Demo {
static void Main() {
string[] arr = { "DemoOne", "DemoTwo", "DemoThree", "DemoFour"};
string res = arr.AsQueryable().Aggregate("DemoFive", (longest, next) => next.Length > longest.Length ? next : longest,str => str.ToLower());
Console.WriteLine("The string with more number of characters: {0}", res);
}
} 출력
The string with more number of characters: demothree