Enumerable.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>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>, 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>(IEnumerable<TSource>, TAccumulate, 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>(IEnumerable<TSource>, Func<TSource,TSource,TSource>) |
Bir dizi üzerinde bir akümülatör işlevi uygular. |
Aggregate<TSource,TAccumulate,TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>, Func<TAccumulate,TResult>)
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.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::Collections::Generic::IEnumerable<TSource> ^ source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> ^ func, Func<TAccumulate, TResult> ^ resultSelector);
public static TResult Aggregate<TSource,TAccumulate,TResult>(this System.Collections.Generic.IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate,TSource,TAccumulate> func, Func<TAccumulate,TResult> resultSelector);
static member Aggregate : seq<'Source> * 'Accumulate * Func<'Accumulate, 'Source, 'Accumulate> * Func<'Accumulate, 'Result> -> 'Result
<Extension()>
Public Function Aggregate(Of TSource, TAccumulate, TResult) (source As IEnumerable(Of TSource), seed As TAccumulate, func As Func(Of TAccumulate, TSource, TAccumulate), resultSelector As 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
- IEnumerable<TSource>
Üzerinde IEnumerable<T> toplanmış bir.
- seed
- TAccumulate
İlk biriktirici değeri.
- func
- Func<TAccumulate,TSource,TAccumulate>
Her öğede çağrılacak bir akümülatör işlevi.
- resultSelector
- 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.
Özel durumlar
source veya func veya resultSelector ş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 gösterir.
string[] fruits = { "apple", "mango", "orange", "passionfruit", "grape" };
// Determine whether any string in the array is longer than "banana".
string longestName =
fruits.Aggregate("banana",
(longest, next) =>
next.Length > longest.Length ? next : longest,
// Return the final result as an upper case 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.
Sub AggregateEx3()
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.Aggregate("banana",
Function(ByVal longest, ByVal fruit) _
IIf(fruit.Length > longest.Length, fruit, longest),
Function(ByVal fruit) fruit.ToUpper())
' Display the output.
Console.WriteLine($"The fruit with the longest name is {longestName}")
End Sub
' This code produces the following output:
'
' The fruit with the longest name is PASSIONFRUIT
Açıklamalar
yöntemi, Aggregate<TSource,TAccumulate,TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>, Func<TAccumulate,TResult>) bir değer dizisi üzerinde hesaplama gerçekleştirmeyi basitleştirir. Bu yöntem, içindeki her öğe için bir kez çağrılarak funcsourceçalışır. Her çağrılır func , Aggregate<TSource,TAccumulate,TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>, Func<TAccumulate,TResult>) hem dizideki öğesini hem de bir toplanmış değeri (ilk bağımsız değişken funcolarak) iletir. parametresinin seed değeri ilk toplama değeri olarak kullanılır. sonucu func , önceki toplanan değerin yerini alır. nihai sonucunu func elde etmek için öğesinin son sonucuna resultSelectorAggregate<TSource,TAccumulate,TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>, Func<TAccumulate,TResult>)geçirilir.
Yaygın toplama işlemlerini basitleştirmek için standart sorgu işleçleri genel amaçlı bir sayı yöntemi Countve , , ve Minolmak üzere MaxSumAveragedört sayısal toplama yöntemi de içerir.
Şunlara uygulanır
Aggregate<TSource,TAccumulate>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>)
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.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::Collections::Generic::IEnumerable<TSource> ^ source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> ^ func);
public static TAccumulate Aggregate<TSource,TAccumulate>(this System.Collections.Generic.IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate,TSource,TAccumulate> func);
static member Aggregate : seq<'Source> * 'Accumulate * Func<'Accumulate, 'Source, 'Accumulate> -> 'Accumulate
<Extension()>
Public Function Aggregate(Of TSource, TAccumulate) (source As IEnumerable(Of TSource), seed As TAccumulate, func As Func(Of TAccumulate, TSource, TAccumulate)) As TAccumulate
Tür Parametreleri
- TSource
öğelerinin sourcetürü.
- TAccumulate
Biriktirici değerinin türü.
Parametreler
- source
- IEnumerable<TSource>
Üzerinde IEnumerable<T> toplanmış bir.
- seed
- TAccumulate
İlk biriktirici değeri.
- func
- Func<TAccumulate,TSource,TAccumulate>
Her öğede çağrılacak bir akümülatör işlevi.
Döndürülenler
Son biriktirici değeri.
Özel durumlar
source veya func şeklindedir null.
Örnekler
Aşağıdaki kod örneği, bir akümülatör işlevi uygulamak ve çekirdek değeri kullanmak için nasıl Aggregate kullanılacağını 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.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
Sub AggregateEx2()
' Create an array of Integers.
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.Aggregate(0,
Function(ByVal total, ByVal number) _
IIf(number Mod 2 = 0, total + 1, total))
' Display the output.
Console.WriteLine($"The number of even integers is {numEven}")
End Sub
' This code produces the following output:
'
'The number of even integers is 6
Açıklamalar
yöntemi, Aggregate<TSource,TAccumulate>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>) bir değer dizisi üzerinde hesaplama gerçekleştirmeyi basitleştirir. Bu yöntem, içindeki her öğe için bir kez çağrılarak funcsourceçalışır. Her çağrılır func , Aggregate<TSource,TAccumulate>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>) hem dizideki öğesini hem de bir toplanmış değeri (ilk bağımsız değişken funcolarak) iletir. parametresinin seed değeri ilk toplama değeri olarak kullanılır. sonucu func , önceki toplanan değerin yerini alır.
Aggregate<TSource,TAccumulate>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate,TSource,TAccumulate>) sonucunu funcdöndürür.
Yaygın toplama işlemlerini basitleştirmek için standart sorgu işleçleri genel amaçlı bir sayı yöntemi Countve , , ve Minolmak üzere MaxSumAveragedört sayısal toplama yöntemi de içerir.
Şunlara uygulanır
Aggregate<TSource>(IEnumerable<TSource>, Func<TSource,TSource,TSource>)
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.cs
- Kaynak:
- Aggregate.cs
Bir dizi üzerinde bir akümülatör işlevi uygular.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static TSource Aggregate(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, TSource, TSource> ^ func);
public static TSource Aggregate<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,TSource,TSource> func);
static member Aggregate : seq<'Source> * Func<'Source, 'Source, 'Source> -> 'Source
<Extension()>
Public Function Aggregate(Of TSource) (source As IEnumerable(Of TSource), func As Func(Of TSource, TSource, TSource)) As TSource
Tür Parametreleri
- TSource
öğelerinin sourcetürü.
Parametreler
- source
- IEnumerable<TSource>
Üzerinde IEnumerable<T> toplanmış bir.
- func
- Func<TSource,TSource,TSource>
Her öğede çağrılacak bir akümülatör işlevi.
Döndürülenler
Son biriktirici değeri.
Özel durumlar
source veya func şeklindedir null.
source öğe içermiyor.
Örnekler
Aşağıdaki kod örneğinde kullanarak Aggregatebir dizedeki sözcüklerin sırasının nasıl tersine çevrildiği gösterilmektedir.
string sentence = "the quick brown fox jumps over the lazy dog";
// Split the string into individual words.
string[] words = sentence.Split(' ');
// Prepend each word to the beginning of the
// new sentence to reverse the word order.
string reversed = words.Aggregate((workingSentence, next) =>
next + " " + workingSentence);
Console.WriteLine(reversed);
// This code produces the following output:
//
// dog lazy the over jumps fox brown quick the
Sub AggregateEx1()
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)
' Prepend each word to the beginning of the new sentence to reverse the word order.
Dim reversed As String =
words.Aggregate(Function(ByVal current, ByVal word) word & " " & current)
' Display the output.
Console.WriteLine(reversed)
End Sub
' This code produces the following output:
'
' dog lazy the over jumps fox brown quick the
Açıklamalar
yöntemi, Aggregate<TSource>(IEnumerable<TSource>, Func<TSource,TSource,TSource>) bir değer dizisi üzerinde hesaplama gerçekleştirmeyi basitleştirir. Bu yöntem, içindeki ilk öğe dışında her öğe func için bir kez çağrılarak source çalışır. Her çağrılır func , Aggregate<TSource>(IEnumerable<TSource>, Func<TSource,TSource,TSource>) hem dizideki öğesini hem de bir toplanmış değeri (ilk bağımsız değişken funcolarak) iletir. öğesinin source ilk öğesi ilk toplama değeri olarak kullanılır. sonucu func , önceki toplanan değerin yerini alır.
Aggregate<TSource>(IEnumerable<TSource>, Func<TSource,TSource,TSource>) sonucunu funcdöndürür.
yönteminin Aggregate bu aşırı yüklemesi, ilk toplama değeri olarak ilk öğesini source kullandığından tüm durumlar için uygun değildir. Dönüş değerinin yalnızca belirli bir koşula uyan öğelerini içermesi source gerekiyorsa başka bir aşırı yükleme seçmelisiniz. Örneğin, içindeki çift sayıların sourcetoplamını hesaplamak istiyorsanız bu aşırı yükleme güvenilir değildir. İlk öğe çift yerine tekse sonuç yanlış olur.
Yaygın toplama işlemlerini basitleştirmek için standart sorgu işleçleri genel amaçlı bir sayı yöntemi Countve , , ve Minolmak üzere MaxSumAveragedört sayısal toplama yöntemi de içerir.