Enumerable.Average Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Oblicza średnią sekwencji wartości liczbowych.
Przeciążenia
| Average(IEnumerable<Single>) |
Oblicza średnią sekwencji Single wartości. |
| Average(IEnumerable<Nullable<Single>>) |
Oblicza średnią sekwencji wartości dopuszczanych Single do wartości null. |
| Average(IEnumerable<Nullable<Int64>>) |
Oblicza średnią sekwencji wartości dopuszczanych Int64 do wartości null. |
| Average(IEnumerable<Nullable<Int32>>) |
Oblicza średnią sekwencji wartości dopuszczanych Int32 do wartości null. |
| Average(IEnumerable<Nullable<Double>>) |
Oblicza średnią sekwencji wartości dopuszczanych Double do wartości null. |
| Average(IEnumerable<Double>) |
Oblicza średnią sekwencji Double wartości. |
| Average(IEnumerable<Int64>) |
Oblicza średnią sekwencji Int64 wartości. |
| Average(IEnumerable<Int32>) |
Oblicza średnią sekwencji Int32 wartości. |
| Average(IEnumerable<Decimal>) |
Oblicza średnią sekwencji Decimal wartości. |
| Average(IEnumerable<Nullable<Decimal>>) |
Oblicza średnią sekwencji wartości dopuszczanych Decimal do wartości null. |
| Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>) |
Oblicza średnią sekwencji wartości dopuszczających wartość null uzyskaną Int32 przez wywołanie funkcji transform dla każdego elementu sekwencji danych wejściowych. |
| Average<TSource>(IEnumerable<TSource>, Func<TSource,Single>) |
Oblicza średnią sekwencji Single wartości uzyskanych przez wywołanie funkcji transform w każdym elemecie sekwencji danych wejściowych. |
| Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>) |
Oblicza średnią sekwencji wartości dopuszczających wartość null uzyskaną Int64 przez wywołanie funkcji transform dla każdego elementu sekwencji danych wejściowych. |
| Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>) |
Oblicza średnią sekwencji wartości dopuszczających wartość null uzyskaną Double przez wywołanie funkcji transform dla każdego elementu sekwencji danych wejściowych. |
| Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>) |
Oblicza średnią sekwencji wartości dopuszczających wartość null uzyskaną Single przez wywołanie funkcji transform dla każdego elementu sekwencji danych wejściowych. |
| Average<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) |
Oblicza średnią sekwencji Int64 wartości uzyskanych przez wywołanie funkcji transform w każdym elemecie sekwencji danych wejściowych. |
| Average<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) |
Oblicza średnią sekwencji Int32 wartości uzyskanych przez wywołanie funkcji transform w każdym elemecie sekwencji danych wejściowych. |
| Average<TSource>(IEnumerable<TSource>, Func<TSource,Double>) |
Oblicza średnią sekwencji Double wartości uzyskanych przez wywołanie funkcji transform w każdym elemecie sekwencji danych wejściowych. |
| Average<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>) |
Oblicza średnią sekwencji Decimal wartości uzyskanych przez wywołanie funkcji transform w każdym elemecie sekwencji danych wejściowych. |
| Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>) |
Oblicza średnią sekwencji wartości dopuszczających wartość null uzyskaną Decimal przez wywołanie funkcji transform dla każdego elementu sekwencji danych wejściowych. |
Average(IEnumerable<Single>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji Single wartości.
public:
[System::Runtime::CompilerServices::Extension]
static float Average(System::Collections::Generic::IEnumerable<float> ^ source);
public static float Average (this System.Collections.Generic.IEnumerable<float> source);
static member Average : seq<single> -> single
<Extension()>
Public Function Average (source As IEnumerable(Of Single)) As Single
Parametry
- source
- IEnumerable<Single>
Sekwencja wartości do Single obliczenia średniej.
Zwraca
Średnia sekwencji wartości.
Wyjątki
source to null.
source nie zawiera żadnych elementów.
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average(IEnumerable<Nullable<Single>>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji wartości dopuszczanych Single do wartości null.
public:
[System::Runtime::CompilerServices::Extension]
static Nullable<float> Average(System::Collections::Generic::IEnumerable<Nullable<float>> ^ source);
public static float? Average (this System.Collections.Generic.IEnumerable<float?> source);
static member Average : seq<Nullable<single>> -> Nullable<single>
<Extension()>
Public Function Average (source As IEnumerable(Of Nullable(Of Single))) As Nullable(Of Single)
Parametry
- source
- IEnumerable<Nullable<Single>>
Sekwencja wartości dopuszczanych Single do wartości null do obliczenia średniej.
Zwraca
Średnia sekwencji wartości lub null jeśli sekwencja źródłowa jest pusta lub zawiera tylko wartości, które są null.
Wyjątki
source to null.
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average(IEnumerable<Nullable<Int64>>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji wartości dopuszczanych Int64 do wartości null.
public:
[System::Runtime::CompilerServices::Extension]
static Nullable<double> Average(System::Collections::Generic::IEnumerable<Nullable<long>> ^ source);
public static double? Average (this System.Collections.Generic.IEnumerable<long?> source);
static member Average : seq<Nullable<int64>> -> Nullable<double>
<Extension()>
Public Function Average (source As IEnumerable(Of Nullable(Of Long))) As Nullable(Of Double)
Parametry
- source
- IEnumerable<Nullable<Int64>>
Sekwencja wartości dopuszczanych Int64 do wartości null do obliczenia średniej.
Zwraca
Średnia sekwencji wartości lub null jeśli sekwencja źródłowa jest pusta lub zawiera tylko wartości, które są null.
Wyjątki
source to null.
Suma elementów w sekwencji jest większa niż Int64.MaxValue.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average(IEnumerable<Nullable<Int64>>) metody obliczania średniej.
long?[] longs = { null, 10007L, 37L, 399846234235L };
double? average = longs.Average();
Console.WriteLine("The average is {0}.", average);
// This code produces the following output:
//
// The average is 133282081426.333.
' Create an array of nullable long values.
Dim longs() As Nullable(Of Long) = {Nothing, 10007L, 37L, 399846234235L}
' Determine the average value in the array.
Dim avg As Nullable(Of Double) = longs.Average()
' Display the output.
Console.WriteLine($"The average is {avg}")
' This code produces the following output:
'
' The average is 133282081426.333
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average(IEnumerable<Nullable<Int32>>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji wartości dopuszczanych Int32 do wartości null.
public:
[System::Runtime::CompilerServices::Extension]
static Nullable<double> Average(System::Collections::Generic::IEnumerable<Nullable<int>> ^ source);
public static double? Average (this System.Collections.Generic.IEnumerable<int?> source);
static member Average : seq<Nullable<int>> -> Nullable<double>
<Extension()>
Public Function Average (source As IEnumerable(Of Nullable(Of Integer))) As Nullable(Of Double)
Parametry
- source
- IEnumerable<Nullable<Int32>>
Sekwencja wartości dopuszczanych Int32 do wartości null do obliczenia średniej.
Zwraca
Średnia sekwencji wartości lub null jeśli sekwencja źródłowa jest pusta lub zawiera tylko wartości, które są null.
Wyjątki
source to null.
Suma elementów w sekwencji jest większa niż Int64.MaxValue.
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average(IEnumerable<Nullable<Double>>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji wartości dopuszczanych Double do wartości null.
public:
[System::Runtime::CompilerServices::Extension]
static Nullable<double> Average(System::Collections::Generic::IEnumerable<Nullable<double>> ^ source);
public static double? Average (this System.Collections.Generic.IEnumerable<double?> source);
static member Average : seq<Nullable<double>> -> Nullable<double>
<Extension()>
Public Function Average (source As IEnumerable(Of Nullable(Of Double))) As Nullable(Of Double)
Parametry
- source
- IEnumerable<Nullable<Double>>
Sekwencja wartości dopuszczanych Double do wartości null do obliczenia średniej.
Zwraca
Średnia sekwencji wartości lub null jeśli sekwencja źródłowa jest pusta lub zawiera tylko wartości, które są null.
Wyjątki
source to null.
Uwagi
Jeśli suma elementów jest zbyt duża do reprezentowania jako , ta metoda zwraca dodatnią lub ujemną Doublenieskończoność.
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average(IEnumerable<Double>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji Double wartości.
public:
[System::Runtime::CompilerServices::Extension]
static double Average(System::Collections::Generic::IEnumerable<double> ^ source);
public static double Average (this System.Collections.Generic.IEnumerable<double> source);
static member Average : seq<double> -> double
<Extension()>
Public Function Average (source As IEnumerable(Of Double)) As Double
Parametry
- source
- IEnumerable<Double>
Sekwencja wartości do Double obliczenia średniej.
Zwraca
Średnia sekwencji wartości.
Wyjątki
source to null.
source nie zawiera żadnych elementów.
Uwagi
Jeśli suma elementów jest zbyt duża do reprezentowania jako , ta metoda zwraca dodatnią lub ujemną Doublenieskończoność.
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average(IEnumerable<Int64>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji Int64 wartości.
public:
[System::Runtime::CompilerServices::Extension]
static double Average(System::Collections::Generic::IEnumerable<long> ^ source);
public static double Average (this System.Collections.Generic.IEnumerable<long> source);
static member Average : seq<int64> -> double
<Extension()>
Public Function Average (source As IEnumerable(Of Long)) As Double
Parametry
- source
- IEnumerable<Int64>
Sekwencja wartości do Int64 obliczenia średniej.
Zwraca
Średnia sekwencji wartości.
Wyjątki
source to null.
source nie zawiera żadnych elementów.
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average(IEnumerable<Int32>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji Int32 wartości.
public:
[System::Runtime::CompilerServices::Extension]
static double Average(System::Collections::Generic::IEnumerable<int> ^ source);
public static double Average (this System.Collections.Generic.IEnumerable<int> source);
static member Average : seq<int> -> double
<Extension()>
Public Function Average (source As IEnumerable(Of Integer)) As Double
Parametry
- source
- IEnumerable<Int32>
Sekwencja wartości do Int32 obliczenia średniej.
Zwraca
Średnia sekwencji wartości.
Wyjątki
source to null.
source nie zawiera żadnych elementów.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average(IEnumerable<Int32>) metody obliczania średniej.
List<int> grades = new List<int> { 78, 92, 100, 37, 81 };
double average = grades.Average();
Console.WriteLine("The average grade is {0}.", average);
// This code produces the following output:
//
// The average grade is 77.6.
' Create a list of integers.
Dim grades As New List(Of Integer)(New Integer() {78, 92, 100, 37, 81})
' Determine the average value in the list.
Dim avg As Double = grades.Average()
' Display the output.
Console.WriteLine($"The average grade is {avg}")
' This code produces the following output:
'
' The average grade is 77.6
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average(IEnumerable<Decimal>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji Decimal wartości.
public:
[System::Runtime::CompilerServices::Extension]
static System::Decimal Average(System::Collections::Generic::IEnumerable<System::Decimal> ^ source);
public static decimal Average (this System.Collections.Generic.IEnumerable<decimal> source);
static member Average : seq<decimal> -> decimal
<Extension()>
Public Function Average (source As IEnumerable(Of Decimal)) As Decimal
Parametry
- source
- IEnumerable<Decimal>
Sekwencja wartości do Decimal obliczenia średniej.
Zwraca
Średnia sekwencji wartości.
Wyjątki
source to null.
source nie zawiera żadnych elementów.
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average(IEnumerable<Nullable<Decimal>>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji wartości dopuszczanych Decimal do wartości null.
public:
[System::Runtime::CompilerServices::Extension]
static Nullable<System::Decimal> Average(System::Collections::Generic::IEnumerable<Nullable<System::Decimal>> ^ source);
public static decimal? Average (this System.Collections.Generic.IEnumerable<decimal?> source);
static member Average : seq<Nullable<decimal>> -> Nullable<decimal>
<Extension()>
Public Function Average (source As IEnumerable(Of Nullable(Of Decimal))) As Nullable(Of Decimal)
Parametry
- source
- IEnumerable<Nullable<Decimal>>
Sekwencja wartości dopuszczanych Decimal do wartości null do obliczenia średniej.
Zwraca
Średnia sekwencji wartości lub null jeśli sekwencja źródłowa jest pusta lub zawiera tylko wartości, które są null.
Wyjątki
source to null.
Suma elementów w sekwencji jest większa niż Decimal.MaxValue.
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji wartości dopuszczających wartość null uzyskaną Int32 przez wywołanie funkcji transform dla każdego elementu sekwencji danych wejściowych.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static Nullable<double> Average(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<int>> ^ selector);
public static double? Average<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,int?> selector);
static member Average : seq<'Source> * Func<'Source, Nullable<int>> -> Nullable<double>
<Extension()>
Public Function Average(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Integer))) As Nullable(Of Double)
Parametry typu
- TSource
Typ elementów elementu source.
Parametry
- source
- IEnumerable<TSource>
Sekwencja wartości do obliczenia średniej.
Zwraca
Średnia sekwencji wartości lub null jeśli sekwencja źródłowa jest pusta lub zawiera tylko wartości, które są null.
Wyjątki
source lub selector to null.
Suma elementów w sekwencji jest większa niż Int64.MaxValue.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) metody obliczania średniej.
Uwaga
W tym przykładzie kodu użyto przeciążenia metody, która różni się od określonego przeciążenia opisanego w tym artykule. Aby rozszerzyć przykład na przeciążenie opisane w tym artykule, zmień treść selector funkcji.
string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape" };
double average = fruits.Average(s => s.Length);
Console.WriteLine("The average string length is {0}.", average);
// This code produces the following output:
//
// The average string length is 6.5.
' Create an array of strings.
Dim fruits() As String =
{"apple", "banana", "mango", "orange", "passionfruit", "grape"}
' Determine the average length of the strings in the array.
Dim avg As Double = fruits.Average(Function(s) s.Length)
' Display the output.
Console.WriteLine($"The average string length is {avg}")
' This code produces the following output:
'
' The average string length is 6.5
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average<TSource>(IEnumerable<TSource>, Func<TSource,Single>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji Single wartości uzyskanych przez wywołanie funkcji transform w każdym elemecie sekwencji danych wejściowych.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static float Average(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, float> ^ selector);
public static float Average<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,float> selector);
static member Average : seq<'Source> * Func<'Source, single> -> single
<Extension()>
Public Function Average(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Single)) As Single
Parametry typu
- TSource
Typ elementów elementu source.
Parametry
- source
- IEnumerable<TSource>
Sekwencja wartości do obliczenia średniej.
Zwraca
Średnia sekwencji wartości.
Wyjątki
source lub selector to null.
source nie zawiera żadnych elementów.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) metody obliczania średniej.
Uwaga
W tym przykładzie kodu użyto przeciążenia metody, która różni się od określonego przeciążenia opisanego w tym artykule. Aby rozszerzyć przykład na przeciążenie opisane w tym artykule, zmień treść selector funkcji.
string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape" };
double average = fruits.Average(s => s.Length);
Console.WriteLine("The average string length is {0}.", average);
// This code produces the following output:
//
// The average string length is 6.5.
' Create an array of strings.
Dim fruits() As String =
{"apple", "banana", "mango", "orange", "passionfruit", "grape"}
' Determine the average length of the strings in the array.
Dim avg As Double = fruits.Average(Function(s) s.Length)
' Display the output.
Console.WriteLine($"The average string length is {avg}")
' This code produces the following output:
'
' The average string length is 6.5
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji wartości dopuszczających wartość null uzyskaną Int64 przez wywołanie funkcji transform dla każdego elementu sekwencji danych wejściowych.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static Nullable<double> Average(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<long>> ^ selector);
public static double? Average<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,long?> selector);
static member Average : seq<'Source> * Func<'Source, Nullable<int64>> -> Nullable<double>
<Extension()>
Public Function Average(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Long))) As Nullable(Of Double)
Parametry typu
- TSource
Typ elementów elementu source.
Parametry
- source
- IEnumerable<TSource>
Sekwencja wartości do obliczenia średniej.
Zwraca
Średnia sekwencji wartości lub null jeśli sekwencja źródłowa jest pusta lub zawiera tylko wartości, które są null.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) metody obliczania średniej.
Uwaga
W tym przykładzie kodu użyto przeciążenia metody, która różni się od określonego przeciążenia opisanego w tym artykule. Aby rozszerzyć przykład na przeciążenie opisane w tym artykule, zmień treść selector funkcji.
string[] numbers = { "10007", "37", "299846234235" };
double average = numbers.Average(num => long.Parse(num));
Console.WriteLine("The average is {0}.", average);
// This code produces the following output:
//
// The average is 99948748093.
' Create an array of strings.
Dim numbers() As String = {"10007", "37", "299846234235"}
' Determine the average number after converting each
' string to an Int64 value.
Dim avg As Double =
numbers.Average(Function(number) Convert.ToInt64(number))
' Display the output.
Console.WriteLine($"The average is {avg}")
' This code produces the following output:
'
' The average is 99948748093
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji wartości dopuszczających wartość null uzyskaną Double przez wywołanie funkcji transform dla każdego elementu sekwencji danych wejściowych.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static Nullable<double> Average(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<double>> ^ selector);
public static double? Average<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,double?> selector);
static member Average : seq<'Source> * Func<'Source, Nullable<double>> -> Nullable<double>
<Extension()>
Public Function Average(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Double))) As Nullable(Of Double)
Parametry typu
- TSource
Typ elementów elementu source.
Parametry
- source
- IEnumerable<TSource>
Sekwencja wartości do obliczenia średniej.
Zwraca
Średnia sekwencji wartości lub null jeśli sekwencja źródłowa jest pusta lub zawiera tylko wartości, które są null.
Wyjątki
source lub selector to null.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) metody obliczania średniej.
Uwaga
W tym przykładzie kodu użyto przeciążenia metody, która różni się od określonego przeciążenia opisanego w tym artykule. Aby rozszerzyć przykład na przeciążenie opisane w tym artykule, zmień treść selector funkcji.
string[] numbers = { "10007", "37", "299846234235" };
double average = numbers.Average(num => long.Parse(num));
Console.WriteLine("The average is {0}.", average);
// This code produces the following output:
//
// The average is 99948748093.
' Create an array of strings.
Dim numbers() As String = {"10007", "37", "299846234235"}
' Determine the average number after converting each
' string to an Int64 value.
Dim avg As Double =
numbers.Average(Function(number) Convert.ToInt64(number))
' Display the output.
Console.WriteLine($"The average is {avg}")
' This code produces the following output:
'
' The average is 99948748093
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji wartości dopuszczających wartość null uzyskaną Single przez wywołanie funkcji transform dla każdego elementu sekwencji danych wejściowych.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static Nullable<float> Average(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<float>> ^ selector);
public static float? Average<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,float?> selector);
static member Average : seq<'Source> * Func<'Source, Nullable<single>> -> Nullable<single>
<Extension()>
Public Function Average(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Single))) As Nullable(Of Single)
Parametry typu
- TSource
Typ elementów elementu source.
Parametry
- source
- IEnumerable<TSource>
Sekwencja wartości do obliczenia średniej.
Zwraca
Średnia sekwencji wartości lub null jeśli sekwencja źródłowa jest pusta lub zawiera tylko wartości, które są null.
Wyjątki
source lub selector to null.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) metody obliczania średniej.
Uwaga
W tym przykładzie kodu użyto przeciążenia metody, która różni się od określonego przeciążenia opisanego w tym artykule. Aby rozszerzyć przykład na przeciążenie opisane w tym artykule, zmień treść selector funkcji.
string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape" };
double average = fruits.Average(s => s.Length);
Console.WriteLine("The average string length is {0}.", average);
// This code produces the following output:
//
// The average string length is 6.5.
' Create an array of strings.
Dim fruits() As String =
{"apple", "banana", "mango", "orange", "passionfruit", "grape"}
' Determine the average length of the strings in the array.
Dim avg As Double = fruits.Average(Function(s) s.Length)
' Display the output.
Console.WriteLine($"The average string length is {avg}")
' This code produces the following output:
'
' The average string length is 6.5
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji Int64 wartości uzyskanych przez wywołanie funkcji transform w każdym elemecie sekwencji danych wejściowych.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static double Average(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, long> ^ selector);
public static double Average<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,long> selector);
static member Average : seq<'Source> * Func<'Source, int64> -> double
<Extension()>
Public Function Average(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Long)) As Double
Parametry typu
- TSource
Typ elementów źródła.
Parametry
- source
- IEnumerable<TSource>
Sekwencja wartości do obliczenia średniej.
Zwraca
Średnia sekwencji wartości.
Wyjątki
source lub selector to null.
source nie zawiera żadnych elementów.
Suma elementów w sekwencji jest większa niż Int64.MaxValue.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) metody obliczania średniej.
string[] numbers = { "10007", "37", "299846234235" };
double average = numbers.Average(num => long.Parse(num));
Console.WriteLine("The average is {0}.", average);
// This code produces the following output:
//
// The average is 99948748093.
' Create an array of strings.
Dim numbers() As String = {"10007", "37", "299846234235"}
' Determine the average number after converting each
' string to an Int64 value.
Dim avg As Double =
numbers.Average(Function(number) Convert.ToInt64(number))
' Display the output.
Console.WriteLine($"The average is {avg}")
' This code produces the following output:
'
' The average is 99948748093
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji Int32 wartości uzyskanych przez wywołanie funkcji transform w każdym elemecie sekwencji danych wejściowych.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static double Average(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, int> ^ selector);
public static double Average<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,int> selector);
static member Average : seq<'Source> * Func<'Source, int> -> double
<Extension()>
Public Function Average(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Integer)) As Double
Parametry typu
- TSource
Typ elementów elementu source.
Parametry
- source
- IEnumerable<TSource>
Sekwencja wartości do obliczenia średniej.
Zwraca
Średnia sekwencji wartości.
Wyjątki
source lub selector to null.
source nie zawiera żadnych elementów.
Suma elementów w sekwencji jest większa niż Int64.MaxValue.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) metody obliczania średniej.
string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape" };
double average = fruits.Average(s => s.Length);
Console.WriteLine("The average string length is {0}.", average);
// This code produces the following output:
//
// The average string length is 6.5.
' Create an array of strings.
Dim fruits() As String =
{"apple", "banana", "mango", "orange", "passionfruit", "grape"}
' Determine the average length of the strings in the array.
Dim avg As Double = fruits.Average(Function(s) s.Length)
' Display the output.
Console.WriteLine($"The average string length is {avg}")
' This code produces the following output:
'
' The average string length is 6.5
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average<TSource>(IEnumerable<TSource>, Func<TSource,Double>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji Double wartości uzyskanych przez wywołanie funkcji transform w każdym elemecie sekwencji danych wejściowych.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static double Average(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, double> ^ selector);
public static double Average<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,double> selector);
static member Average : seq<'Source> * Func<'Source, double> -> double
<Extension()>
Public Function Average(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Double)) As Double
Parametry typu
- TSource
Typ elementów elementu source.
Parametry
- source
- IEnumerable<TSource>
Sekwencja wartości do obliczenia średniej.
Zwraca
Średnia sekwencji wartości.
Wyjątki
source lub selector to null.
source nie zawiera żadnych elementów.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) metody obliczania średniej.
Uwaga
W tym przykładzie kodu użyto przeciążenia metody, która różni się od określonego przeciążenia opisanego w tym artykule. Aby rozszerzyć przykład na przeciążenie opisane w tym artykule, zmień treść selector funkcji.
string[] numbers = { "10007", "37", "299846234235" };
double average = numbers.Average(num => long.Parse(num));
Console.WriteLine("The average is {0}.", average);
// This code produces the following output:
//
// The average is 99948748093.
' Create an array of strings.
Dim numbers() As String = {"10007", "37", "299846234235"}
' Determine the average number after converting each
' string to an Int64 value.
Dim avg As Double =
numbers.Average(Function(number) Convert.ToInt64(number))
' Display the output.
Console.WriteLine($"The average is {avg}")
' This code produces the following output:
'
' The average is 99948748093
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji Decimal wartości uzyskanych przez wywołanie funkcji transform w każdym elemecie sekwencji danych wejściowych.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static System::Decimal Average(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, System::Decimal> ^ selector);
public static decimal Average<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,decimal> selector);
static member Average : seq<'Source> * Func<'Source, decimal> -> decimal
<Extension()>
Public Function Average(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Decimal)) As Decimal
Parametry typu
- TSource
Typ elementów elementu source.
Parametry
- source
- IEnumerable<TSource>
Sekwencja wartości używanych do obliczania średniej.
Zwraca
Średnia sekwencji wartości.
Wyjątki
source lub selector to null.
source nie zawiera żadnych elementów.
Suma elementów w sekwencji jest większa niż Decimal.MaxValue.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) metody obliczania średniej.
Uwaga
W tym przykładzie kodu użyto przeciążenia metody, która różni się od określonego przeciążenia opisanego w tym artykule. Aby rozszerzyć przykład na przeciążenie opisane w tym artykule, zmień treść selector funkcji.
string[] numbers = { "10007", "37", "299846234235" };
double average = numbers.Average(num => long.Parse(num));
Console.WriteLine("The average is {0}.", average);
// This code produces the following output:
//
// The average is 99948748093.
' Create an array of strings.
Dim numbers() As String = {"10007", "37", "299846234235"}
' Determine the average number after converting each
' string to an Int64 value.
Dim avg As Double =
numbers.Average(Function(number) Convert.ToInt64(number))
' Display the output.
Console.WriteLine($"The average is {avg}")
' This code produces the following output:
'
' The average is 99948748093
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .
Zobacz też
Dotyczy
Average<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)
- Źródło:
- Average.cs
- Źródło:
- Average.cs
- Źródło:
- Average.cs
Oblicza średnią sekwencji wartości dopuszczających wartość null uzyskaną Decimal przez wywołanie funkcji transform dla każdego elementu sekwencji danych wejściowych.
public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
static Nullable<System::Decimal> Average(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<System::Decimal>> ^ selector);
public static decimal? Average<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,decimal?> selector);
static member Average : seq<'Source> * Func<'Source, Nullable<decimal>> -> Nullable<decimal>
<Extension()>
Public Function Average(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Decimal))) As Nullable(Of Decimal)
Parametry typu
- TSource
Typ elementów elementu source.
Parametry
- source
- IEnumerable<TSource>
Sekwencja wartości do obliczenia średniej.
Zwraca
Średnia sekwencji wartości lub null jeśli sekwencja źródłowa jest pusta lub zawiera tylko wartości, które są null.
Wyjątki
source lub selector to null.
Suma elementów w sekwencji jest większa niż Decimal.MaxValue.
Przykłady
W poniższym przykładzie kodu pokazano, jak użyć Average<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) metody obliczania średniej.
Uwaga
W tym przykładzie kodu użyto przeciążenia metody, która różni się od określonego przeciążenia opisanego w tym artykule. Aby rozszerzyć przykład na przeciążenie opisane w tym artykule, zmień treść selector funkcji.
string[] numbers = { "10007", "37", "299846234235" };
double average = numbers.Average(num => long.Parse(num));
Console.WriteLine("The average is {0}.", average);
// This code produces the following output:
//
// The average is 99948748093.
' Create an array of strings.
Dim numbers() As String = {"10007", "37", "299846234235"}
' Determine the average number after converting each
' string to an Int64 value.
Dim avg As Double =
numbers.Average(Function(number) Convert.ToInt64(number))
' Display the output.
Console.WriteLine($"The average is {avg}")
' This code produces the following output:
'
' The average is 99948748093
Uwagi
W składni wyrażenia zapytania języka Visual Basic klauzula Aggregate Into Average() tłumaczy się na wywołanie Averageelementu .