Queryable.Aggregate 메서드

정의

오버로드

Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate, TResult>>)

시퀀스에 누적기 함수를 적용합니다. 지정된 시드 값은 초기 누적기 값으로 사용되고 지정된 함수는 결과 값을 선택하는 데 사용됩니다.

Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>)

시퀀스에 누적기 함수를 적용합니다. 지정된 시드 값은 초기 누적기 값으로 사용됩니다.

Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>)

시퀀스에 누적기 함수를 적용합니다.

Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate, TResult>>)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

시퀀스에 누적기 함수를 적용합니다. 지정된 시드 값은 초기 누적기 값으로 사용되고 지정된 함수는 결과 값을 선택하는 데 사용됩니다.

public:
generic <typename TSource, typename TAccumulate, typename TResult>
[System::Runtime::CompilerServices::Extension]
 static TResult Aggregate(System::Linq::IQueryable<TSource> ^ source, TAccumulate seed, System::Linq::Expressions::Expression<Func<TAccumulate, TSource, TAccumulate> ^> ^ func, System::Linq::Expressions::Expression<Func<TAccumulate, TResult> ^> ^ selector);
public static TResult Aggregate<TSource,TAccumulate,TResult> (this System.Linq.IQueryable<TSource> source, TAccumulate seed, System.Linq.Expressions.Expression<Func<TAccumulate,TSource,TAccumulate>> func, System.Linq.Expressions.Expression<Func<TAccumulate,TResult>> selector);
static member Aggregate : System.Linq.IQueryable<'Source> * 'Accumulate * System.Linq.Expressions.Expression<Func<'Accumulate, 'Source, 'Accumulate>> * System.Linq.Expressions.Expression<Func<'Accumulate, 'Result>> -> 'Result
<Extension()>
Public Function Aggregate(Of TSource, TAccumulate, TResult) (source As IQueryable(Of TSource), seed As TAccumulate, func As Expression(Of Func(Of TAccumulate, TSource, TAccumulate)), selector As Expression(Of Func(Of TAccumulate, TResult))) As TResult

형식 매개 변수

TSource

source 요소의 형식입니다.

TAccumulate

누적기 값의 형식입니다.

TResult

결과 값의 형식입니다.

매개 변수

source
IQueryable<TSource>

집계할 시퀀스입니다.

seed
TAccumulate

초기 누적기 값입니다.

func
Expression<Func<TAccumulate,TSource,TAccumulate>>

각 요소에 대해 호출할 누적기 함수입니다.

selector
Expression<Func<TAccumulate,TResult>>

최종 누적기 값을 결과 값으로 변환하는 함수입니다.

반환

TResult

변환된 최종 누적기 값입니다.

예외

source, func 또는 selectornull인 경우

예제

다음 코드 예제에서는 를 사용하여 Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate, TResult>>) 누적기 함수 및 결과 선택기를 적용하는 방법을 보여 줍니다.

string[] fruits = { "apple", "mango", "orange", "passionfruit", "grape" };

// Determine whether any string in the array is longer than "banana".
string longestName =
    fruits.AsQueryable().Aggregate(
    "banana",
    (longest, next) => next.Length > longest.Length ? next : longest,
    // Return the final result as an uppercase string.
    fruit => fruit.ToUpper()
    );

Console.WriteLine(
    "The fruit with the longest name is {0}.",
    longestName);

// This code produces the following output:
//
// The fruit with the longest name is PASSIONFRUIT.
Dim fruits() As String = {"apple", "mango", "orange", "passionfruit", "grape"}

' Determine whether any string in the array is longer than "banana".
Dim longestName As String = _
    fruits.AsQueryable().Aggregate( _
    "banana", _
    Function(ByVal longest, ByVal fruit) IIf(fruit.Length > longest.Length, fruit, longest), _
    Function(ByVal fruit) fruit.ToUpper() _
)

MsgBox(String.Format( _
    "The fruit with the longest name is {0}.", longestName) _
)

' This code produces the following output:
'
' The fruit with the longest name is PASSIONFRUIT.

설명

이 메서드에는 형식 인수가 형식 중 하나인 형식 Expression<TDelegate> 의 매개 변수가 Func<T,TResult> 하나 이상 있습니다. 이러한 매개 변수의 경우 람다 식을 전달할 수 있으며 에 컴파일됩니다 Expression<TDelegate>.

메서드는 Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate, TResult>>)MethodCallExpression 생성된 제네릭 메서드로 자신을 호출 Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate, TResult>>) 하는 를 나타내는 을 생성합니다. 그런 다음 을 MethodCallExpression 매개 변수의 Execute<TResult>(Expression) 속성으로 나타내는 의 IQueryProvider 메서드에 Providersource 전달합니다.

호출 Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate, TResult>>) 을 나타내는 식 트리를 실행한 결과로 발생하는 쿼리 동작은 매개 변수 형식의 source 구현에 따라 달라집니다. 예상 동작은 지정된 함수 가 func소스 시퀀스의 각 값에 적용되고 누적된 값이 반환된다는 것입니다. seed 매개 변수는 의 첫 번째 매개 변수func에 해당하는 누적된 값의 시드 값으로 사용됩니다. 최종 누적 값은 결과 값을 얻기 위해 에 selector 전달됩니다.

일반적인 집계 작업을 간소화하기 위해 표준 쿼리 연산자 집합에는 두 개의 카운팅 메서드 Count 와 , 및 LongCount4개의 숫자 집계 메서드, 즉 Max, , MinSumAverage도 포함됩니다.

적용 대상

Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

시퀀스에 누적기 함수를 적용합니다. 지정된 시드 값은 초기 누적기 값으로 사용됩니다.

public:
generic <typename TSource, typename TAccumulate>
[System::Runtime::CompilerServices::Extension]
 static TAccumulate Aggregate(System::Linq::IQueryable<TSource> ^ source, TAccumulate seed, System::Linq::Expressions::Expression<Func<TAccumulate, TSource, TAccumulate> ^> ^ func);
public static TAccumulate Aggregate<TSource,TAccumulate> (this System.Linq.IQueryable<TSource> source, TAccumulate seed, System.Linq.Expressions.Expression<Func<TAccumulate,TSource,TAccumulate>> func);
static member Aggregate : System.Linq.IQueryable<'Source> * 'Accumulate * System.Linq.Expressions.Expression<Func<'Accumulate, 'Source, 'Accumulate>> -> 'Accumulate
<Extension()>
Public Function Aggregate(Of TSource, TAccumulate) (source As IQueryable(Of TSource), seed As TAccumulate, func As Expression(Of Func(Of TAccumulate, TSource, TAccumulate))) As TAccumulate

형식 매개 변수

TSource

source 요소의 형식입니다.

TAccumulate

누적기 값의 형식입니다.

매개 변수

source
IQueryable<TSource>

집계할 시퀀스입니다.

seed
TAccumulate

초기 누적기 값입니다.

func
Expression<Func<TAccumulate,TSource,TAccumulate>>

각 요소에 대해 호출할 누적기 함수입니다.

반환

TAccumulate

최종 누적기 값입니다.

예외

source 또는 funcnull인 경우

예제

다음 코드 예제에서는 를 사용하여 Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>) 시드 값이 함수에 제공될 때 누적기 함수를 적용하는 방법을 보여 줍니다.

int[] ints = { 4, 8, 8, 3, 9, 0, 7, 8, 2 };

// Count the even numbers in the array, using a seed value of 0.
int numEven =
    ints.AsQueryable().Aggregate(
    0,
    (total, next) => next % 2 == 0 ? total + 1 : total
    );

Console.WriteLine("The number of even integers is: {0}", numEven);

// This code produces the following output:
//
// The number of even integers is: 6
Dim ints() As Integer = {4, 8, 8, 3, 9, 0, 7, 8, 2}

' Count the even numbers in the array, using a seed value of 0.
Dim numEven As Integer = _
    ints.AsQueryable().Aggregate( _
        0, _
        Function(ByVal total, ByVal number) _
            IIf(number Mod 2 = 0, total + 1, total) _
    )

MsgBox(String.Format("The number of even integers is: {0}", numEven))

' This code produces the following output:
'
' The number of even integers is: 6

설명

이 메서드에는 형식 인수가 형식 중 하나인 형식 Expression<TDelegate> 의 매개 변수가 Func<T,TResult> 하나 이상 있습니다. 이러한 매개 변수의 경우 람다 식을 전달할 수 있으며 에 컴파일됩니다 Expression<TDelegate>.

메서드는 Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>)MethodCallExpression 생성된 제네릭 메서드로 자신을 호출 Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>) 하는 를 나타내는 을 생성합니다. 그런 다음 을 MethodCallExpression 매개 변수의 Execute<TResult>(Expression) 속성으로 나타내는 의 IQueryProvider 메서드에 Providersource 전달합니다.

호출 Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>) 을 나타내는 식 트리를 실행한 결과로 발생하는 쿼리 동작은 매개 변수 형식의 source 구현에 따라 달라집니다. 예상 동작은 지정된 함수 가 func소스 시퀀스의 각 값에 적용되고 누적된 값이 반환된다는 것입니다. seed 매개 변수는 의 첫 번째 매개 변수func에 해당하는 누적된 값의 시드 값으로 사용됩니다.

일반적인 집계 작업을 간소화하기 위해 표준 쿼리 연산자 집합에는 두 개의 카운팅 메서드 Count 와 , 및 LongCount4개의 숫자 집계 메서드, 즉 Max, , MinSumAverage도 포함됩니다.

적용 대상

Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

시퀀스에 누적기 함수를 적용합니다.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource Aggregate(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, TSource, TSource> ^> ^ func);
public static TSource Aggregate<TSource> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,TSource,TSource>> func);
static member Aggregate : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, 'Source, 'Source>> -> 'Source
<Extension()>
Public Function Aggregate(Of TSource) (source As IQueryable(Of TSource), func As Expression(Of Func(Of TSource, TSource, TSource))) As TSource

형식 매개 변수

TSource

source 요소의 형식입니다.

매개 변수

source
IQueryable<TSource>

집계할 시퀀스입니다.

func
Expression<Func<TSource,TSource,TSource>>

각 요소에 적용할 누적기 함수입니다.

반환

TSource

최종 누적기 값입니다.

예외

source 또는 funcnull인 경우

source에 요소가 없는 경우

예제

다음 코드 예제에서는 를 사용하여 Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>) 문자열 배열에서 문장을 작성하는 방법을 보여 줍니다.

string sentence = "the quick brown fox jumps over the lazy dog";

// Split the string into individual words.
string[] words = sentence.Split(' ');

// Use Aggregate() to prepend each word to the beginning of the
// new sentence to reverse the word order.
string reversed =
    words.AsQueryable().Aggregate(
    (workingSentence, next) => next + " " + workingSentence
    );

Console.WriteLine(reversed);

// This code produces the following output:
//
// dog lazy the over jumps fox brown quick the
Dim sentence As String = "the quick brown fox jumps over the lazy dog"

' Split the string into individual words.
Dim words() As String = sentence.Split(" "c)

' Use Aggregate() to prepend each word to the beginning of the 
' new sentence to reverse the word order.
Dim reversed As String = _
    words.AsQueryable().Aggregate( _
        Function(ByVal workingSentence, ByVal nextWord) nextWord & " " & workingSentence _
    )

MsgBox(reversed)

' This code produces the following output:
'
' dog lazy the over jumps fox brown quick the

설명

이 메서드에는 형식 인수가 형식 중 하나인 형식 Expression<TDelegate> 의 매개 변수가 Func<T,TResult> 하나 이상 있습니다. 이러한 매개 변수의 경우 람다 식을 전달할 수 있으며 에 컴파일됩니다 Expression<TDelegate>.

메서드는 Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>)MethodCallExpression 생성된 제네릭 메서드로 자신을 호출 Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>) 하는 를 나타내는 을 생성합니다. 그런 다음 을 MethodCallExpression 매개 변수의 Execute<TResult>(Expression) 속성으로 나타내는 의 IQueryProvider 메서드에 Providersource 전달합니다.

호출 Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>) 을 나타내는 식 트리를 실행한 결과로 발생하는 쿼리 동작은 매개 변수 형식의 source 구현에 따라 달라집니다. 예상 동작은 지정된 함수 가 func소스 시퀀스의 각 값에 적용되고 누적된 값이 반환된다는 것입니다. 의 source 첫 번째 값은 의 첫 번째 매개 변수 func에 해당하는 누적된 값의 시드 값으로 사용됩니다.

일반적인 집계 작업을 간소화하기 위해 표준 쿼리 연산자 집합에는 두 개의 카운팅 메서드 Count 와 , 및 LongCount4개의 숫자 집계 메서드, 즉 Max, , MinSumAverage도 포함됩니다.

적용 대상