Queryable.Aggregate Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Aşırı Yüklemeler
| Name | Description |
|---|---|
| Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate, TResult>>) |
Bir dizi üzerinde bir akümülatör işlevi uygular. Belirtilen çekirdek değeri ilk biriktirici değeri olarak kullanılır ve belirtilen işlev sonuç değerini seçmek için kullanılır. |
| Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>) |
Bir dizi üzerinde bir akümülatör işlevi uygular. Belirtilen çekirdek değeri ilk biriktirici değeri olarak kullanılır. |
| Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>) |
Bir dizi üzerinde bir akümülatör işlevi uygular. |
Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate, TResult>>)
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
Bir dizi üzerinde bir akümülatör işlevi uygular. Belirtilen çekirdek değeri ilk biriktirici değeri olarak kullanılır ve belirtilen işlev sonuç değerini seçmek için kullanılır.
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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
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
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
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
Tür Parametreleri
- TSource
öğelerinin sourcetürü.
- TAccumulate
Biriktirici değerinin türü.
- TResult
Sonuçta elde edilen değerin türü.
Parametreler
- source
- IQueryable<TSource>
Toplanmış bir dizi.
- seed
- TAccumulate
İlk biriktirici değeri.
- func
- Expression<Func<TAccumulate,TSource,TAccumulate>>
Her öğede çağrılacak bir akümülatör işlevi.
- selector
- Expression<Func<TAccumulate,TResult>>
Son akümülatör değerini sonuç değerine dönüştüren bir işlev.
Döndürülenler
Dönüştürülen son biriktirici değeri.
- Öznitelikler
Özel durumlar
source veya func veya selector şeklindedir null.
Örnekler
Aşağıdaki kod örneği, bir biriktirici işlevi ve sonuç seçici uygulamak için nasıl kullanılacağını Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate, TResult>>) gösterir.
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.
Açıklamalar
Bu yöntem, tür bağımsız değişkeni türlerden Expression<TDelegate> biri olan en az bir tür parametresine Func<T,TResult> sahiptir. Bu parametreler için bir lambda ifadesi geçirebilirsiniz ve bu ifade bir Expression<TDelegate>olarak derlenir.
yöntemi, Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate,
Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate,
TResult>>) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağıran Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate,
Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate,
TResult>>) bir oluşturur. Ardından parametresinin özelliği tarafından Provider temsil edilen yöntemine sourceIQueryProvider iletirMethodCallExpression.Execute<TResult>(Expression)
Çağrıyı Aggregate<TSource,TAccumulate,TResult>(IQueryable<TSource>, TAccumulate,
Expression<Func<TAccumulate,TSource,TAccumulate>>, Expression<Func<TAccumulate,
TResult>>) temsil eden bir ifade ağacının yürütülmesi sonucunda oluşan sorgu davranışı, parametre türünün uygulanmasına source bağlıdır. Beklenen davranış, funcbelirtilen işlevin kaynak dizideki her değere uygulanması ve birikmiş değerin döndürülmesidir.
seed parametresi, içindeki ilk parametreye funckarşılık gelen birikmiş değerin tohum değeri olarak kullanılır. Son birikmiş değer, sonuç değerini almak için öğesine selector geçirilir.
Yaygın toplama işlemlerini basitleştirmek için, standart sorgu işleçleri kümesi iki sayım yöntemi Count ve LongCountve dört sayısal toplama yöntemi (, , ve Average) MaxMinSumiçerir.
Şunlara uygulanır
Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>)
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
Bir dizi üzerinde bir akümülatör işlevi uygular. Belirtilen çekirdek değeri ilk biriktirici değeri olarak kullanılır.
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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
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
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
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
Tür Parametreleri
- TSource
öğelerinin sourcetürü.
- TAccumulate
Biriktirici değerinin türü.
Parametreler
- source
- IQueryable<TSource>
Toplanmış bir dizi.
- seed
- TAccumulate
İlk biriktirici değeri.
- func
- Expression<Func<TAccumulate,TSource,TAccumulate>>
Her öğede çağrılacak bir akümülatör işlevi.
Döndürülenler
Son biriktirici değeri.
- Öznitelikler
Özel durumlar
source veya func şeklindedir null.
Örnekler
Aşağıdaki kod örneği, işleve bir çekirdek değeri sağlandığında bir akümülatör işlevini uygulamak için nasıl kullanılacağını Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>) gösterir.
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
Açıklamalar
Bu yöntem, tür bağımsız değişkeni türlerden Expression<TDelegate> biri olan en az bir tür parametresine Func<T,TResult> sahiptir. Bu parametreler için bir lambda ifadesi geçirebilirsiniz ve bu ifade bir Expression<TDelegate>olarak derlenir.
yöntemi, Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağıran Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>) bir oluşturur. Ardından parametresinin özelliği tarafından Provider temsil edilen yöntemine sourceIQueryProvider iletirMethodCallExpression.Execute<TResult>(Expression)
Çağrıyı Aggregate<TSource,TAccumulate>(IQueryable<TSource>, TAccumulate, Expression<Func<TAccumulate,TSource,TAccumulate>>) temsil eden bir ifade ağacının yürütülmesi sonucunda oluşan sorgu davranışı, parametre türünün uygulanmasına source bağlıdır. Beklenen davranış, funcbelirtilen işlevin kaynak dizideki her değere uygulanması ve birikmiş değerin döndürülmesidir.
seed parametresi, içindeki ilk parametreye funckarşılık gelen birikmiş değerin tohum değeri olarak kullanılır.
Yaygın toplama işlemlerini basitleştirmek için, standart sorgu işleçleri kümesi iki sayım yöntemi Count ve LongCountve dört sayısal toplama yöntemi (, , ve Average) MaxMinSumiçerir.
Şunlara uygulanır
Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>)
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
- Kaynak:
- Queryable.cs
Bir dizi üzerinde bir akümülatör işlevi uygular.
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);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
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
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")>]
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
Tür Parametreleri
- TSource
öğelerinin sourcetürü.
Parametreler
- source
- IQueryable<TSource>
Toplanmış bir dizi.
- func
- Expression<Func<TSource,TSource,TSource>>
Her öğeye uygulanacak bir akümülatör işlevi.
Döndürülenler
Son biriktirici değeri.
- Öznitelikler
Özel durumlar
source veya func şeklindedir null.
source öğe içermiyor.
Örnekler
Aşağıdaki kod örneği, dize dizisinden bir tümce oluşturmak için nasıl kullanılacağını Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>) gösterir.
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
Açıklamalar
Bu yöntem, tür bağımsız değişkeni türlerden Expression<TDelegate> biri olan en az bir tür parametresine Func<T,TResult> sahiptir. Bu parametreler için bir lambda ifadesi geçirebilirsiniz ve bu ifade bir Expression<TDelegate>olarak derlenir.
yöntemi, Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>) kendisini oluşturulan genel bir MethodCallExpression yöntem olarak çağıran Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>) bir oluşturur. Ardından parametresinin özelliği tarafından Provider temsil edilen yöntemine sourceIQueryProvider iletirMethodCallExpression.Execute<TResult>(Expression)
Çağrıyı Aggregate<TSource>(IQueryable<TSource>, Expression<Func<TSource,TSource,TSource>>) temsil eden bir ifade ağacının yürütülmesi sonucunda oluşan sorgu davranışı, parametre türünün uygulanmasına source bağlıdır. Beklenen davranış, funcbelirtilen işlevin kaynak dizideki her değere uygulanması ve birikmiş değerin döndürülmesidir. içindeki source ilk değer, içindeki ilk parametreye funckarşılık gelen birikmiş değerin tohum değeri olarak kullanılır.
Yaygın toplama işlemlerini basitleştirmek için, standart sorgu işleçleri kümesi iki sayım yöntemi Count ve LongCountve dört sayısal toplama yöntemi (, , ve Average) MaxMinSumiçerir.