728x90
728x170

시퀀스에 누적함수를 적용할때 사용됩니다.
 

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#] Indexer  (0) 2023.10.17
[C#] ArvoConvert 사용하기  (0) 2023.10.10
[C#] Liquid Template 사용하기 - Fluid  (0) 2023.09.21
[C#/Blazor] FluentUI Icon - Microsoft.Fast.Components.FluentUI.Icons  (0) 2023.09.20
[C#/Oracle] Oracle Parameter 순서  (0) 2023.09.19
Posted by kjun
,