Queryable.Average メソッド

定義

数値のシーケンスの平均を計算します。

オーバーロード

Average(IQueryable<Single>)

Single 値のシーケンスの平均値を計算します。

Average(IQueryable<Nullable<Int64>>)

Null 許容型の Int64 値のシーケンスの平均を計算します。

Average(IQueryable<Nullable<Int32>>)

Null 許容型の Int32 値のシーケンスの平均を計算します。

Average(IQueryable<Nullable<Double>>)

Null 許容型の Double 値のシーケンスの平均を計算します。

Average(IQueryable<Nullable<Single>>)

Null 許容型の Single 値のシーケンスの平均を計算します。

Average(IQueryable<Int64>)

Int64 値のシーケンスの平均値を計算します。

Average(IQueryable<Int32>)

Int32 値のシーケンスの平均値を計算します。

Average(IQueryable<Double>)

Double 値のシーケンスの平均値を計算します。

Average(IQueryable<Decimal>)

Decimal 値のシーケンスの平均値を計算します。

Average(IQueryable<Nullable<Decimal>>)

Null 許容型の Decimal 値のシーケンスの平均を計算します。

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>)

入力シーケンスの各要素に対して射影関数を呼び出して取得する Single 値のシーケンスの平均値を計算します。

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>)

入力シーケンスの各要素に対して射影関数を呼び出して取得する、null 許容の Single 値のシーケンスの平均値を計算します。

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>)

入力シーケンスの各要素に対して射影関数を呼び出して取得する、null 許容の Int64 値のシーケンスの平均値を計算します。

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>)

入力シーケンスの各要素に対して射影関数を呼び出して取得する、null 許容の Double 値のシーケンスの平均値を計算します。

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>)

入力シーケンスの各要素に対して射影関数を呼び出して取得する、null 許容の Int32 値のシーケンスの平均値を計算します。

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>)

入力シーケンスの各要素に対して射影関数を呼び出して取得する Int64 値のシーケンスの平均値を計算します。

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)

入力シーケンスの各要素に対して射影関数を呼び出して取得する Int32 値のシーケンスの平均値を計算します。

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>)

入力シーケンスの各要素に対して射影関数を呼び出して取得する Double 値のシーケンスの平均値を計算します。

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>)

入力シーケンスの各要素に対して射影関数を呼び出して取得する Decimal 値のシーケンスの平均値を計算します。

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>)

入力シーケンスの各要素に対して射影関数を呼び出して取得する、null 許容の Decimal 値のシーケンスの平均値を計算します。

Average(IQueryable<Single>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

Single 値のシーケンスの平均値を計算します。

public:
[System::Runtime::CompilerServices::Extension]
 static float Average(System::Linq::IQueryable<float> ^ source);
public static float Average (this System.Linq.IQueryable<float> source);
static member Average : System.Linq.IQueryable<single> -> single
<Extension()>
Public Function Average (source As IQueryable(Of Single)) As Single

パラメーター

source
IQueryable<Single>

平均値計算の対象となる Single 値のシーケンス。

戻り値

値のシーケンスの平均値。

例外

sourcenullです。

source に要素が含まれていません。

次のコード例では、 を使用 Average(IQueryable<Int32>) して一連の値の平均を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この例をこの記事で説明するオーバーロードに拡張するには、ソース シーケンスの要素を適切な数値型の要素に置き換える必要があります。

List<int> grades = new List<int> { 78, 92, 100, 37, 81 };

double average = grades.AsQueryable().Average();

Console.WriteLine("The average grade is {0}.", average);

// This code produces the following output:
//
// The average grade is 77.6.
Dim grades As New List(Of Integer)(New Integer() {78, 92, 100, 37, 81})

Dim average As Double = grades.AsQueryable().Average()

MsgBox(String.Format("The average grade is {0}.", average))

' This code produces the following output:
'
' The average grade is 77.6.

注釈

メソッドは Average(IQueryable<Single>)MethodCallExpression 呼び出し Average(IQueryable<Single>) 元自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average(IQueryable<Single>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、 の source値の平均を計算することです。

適用対象

Average(IQueryable<Nullable<Int64>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

Null 許容型の Int64 値のシーケンスの平均を計算します。

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<double> Average(System::Linq::IQueryable<Nullable<long>> ^ source);
public static double? Average (this System.Linq.IQueryable<long?> source);
static member Average : System.Linq.IQueryable<Nullable<int64>> -> Nullable<double>
<Extension()>
Public Function Average (source As IQueryable(Of Nullable(Of Long))) As Nullable(Of Double)

パラメーター

source
IQueryable<Nullable<Int64>>

平均を計算する Null 許容型の Int64 値のシーケンス。

戻り値

値のシーケンスの平均値、または、ソース シーケンスが空または null である値のみを含む場合は null

例外

sourcenullです。

次のコード例では、 を使用 Average(IQueryable<Nullable<Int64>>) して一連の値の平均を計算する方法を示します。

long?[] longs = { null, 10007L, 37L, 399846234235L };

double? average = longs.AsQueryable().Average();

Console.WriteLine("The average is {0}.", average);

// This code produces the following output:
//
// The average is 133282081426.333.
Dim longs() As Nullable(Of Long) = {Nothing, 10007L, 37L, 399846234235L}

Dim average As Nullable(Of Double) = longs.AsQueryable().Average()

MsgBox(String.Format("The average is {0}.", average))

' This code produces the following output:
'
' The average is 133282081426.333.

注釈

メソッドは Average(IQueryable<Nullable<Int64>>)MethodCallExpression 呼び出し Average(IQueryable<Nullable<Int64>>) 元自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average(IQueryable<Nullable<Int64>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、 の source値の平均を計算することです。

適用対象

Average(IQueryable<Nullable<Int32>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

Null 許容型の Int32 値のシーケンスの平均を計算します。

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<double> Average(System::Linq::IQueryable<Nullable<int>> ^ source);
public static double? Average (this System.Linq.IQueryable<int?> source);
static member Average : System.Linq.IQueryable<Nullable<int>> -> Nullable<double>
<Extension()>
Public Function Average (source As IQueryable(Of Nullable(Of Integer))) As Nullable(Of Double)

パラメーター

source
IQueryable<Nullable<Int32>>

平均を計算する Null 許容型の Int32 値のシーケンス。

戻り値

値のシーケンスの平均値、または、ソース シーケンスが空または null である値のみを含む場合は null

例外

sourcenullです。

次のコード例では、 を使用 Average(IQueryable<Nullable<Int64>>) して一連の値の平均を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この例をこの記事で説明するオーバーロードに拡張するには、ソース シーケンスの要素を適切な数値型の要素に置き換える必要があります。

long?[] longs = { null, 10007L, 37L, 399846234235L };

double? average = longs.AsQueryable().Average();

Console.WriteLine("The average is {0}.", average);

// This code produces the following output:
//
// The average is 133282081426.333.
Dim longs() As Nullable(Of Long) = {Nothing, 10007L, 37L, 399846234235L}

Dim average As Nullable(Of Double) = longs.AsQueryable().Average()

MsgBox(String.Format("The average is {0}.", average))

' This code produces the following output:
'
' The average is 133282081426.333.

注釈

メソッドは Average(IQueryable<Nullable<Int32>>)MethodCallExpression 呼び出し Average(IQueryable<Nullable<Int32>>) 元自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average(IQueryable<Nullable<Int32>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、 の source値の平均を計算することです。

適用対象

Average(IQueryable<Nullable<Double>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

Null 許容型の Double 値のシーケンスの平均を計算します。

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<double> Average(System::Linq::IQueryable<Nullable<double>> ^ source);
public static double? Average (this System.Linq.IQueryable<double?> source);
static member Average : System.Linq.IQueryable<Nullable<double>> -> Nullable<double>
<Extension()>
Public Function Average (source As IQueryable(Of Nullable(Of Double))) As Nullable(Of Double)

パラメーター

source
IQueryable<Nullable<Double>>

平均を計算する Null 許容型の Double 値のシーケンス。

戻り値

値のシーケンスの平均値、または、ソース シーケンスが空または null である値のみを含む場合は null

例外

sourcenullです。

次のコード例では、 を使用 Average(IQueryable<Nullable<Int64>>) して一連の値の平均を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この例をこの記事で説明するオーバーロードに拡張するには、ソース シーケンスの要素を適切な数値型の要素に置き換える必要があります。

long?[] longs = { null, 10007L, 37L, 399846234235L };

double? average = longs.AsQueryable().Average();

Console.WriteLine("The average is {0}.", average);

// This code produces the following output:
//
// The average is 133282081426.333.
Dim longs() As Nullable(Of Long) = {Nothing, 10007L, 37L, 399846234235L}

Dim average As Nullable(Of Double) = longs.AsQueryable().Average()

MsgBox(String.Format("The average is {0}.", average))

' This code produces the following output:
'
' The average is 133282081426.333.

注釈

メソッドは Average(IQueryable<Nullable<Double>>)MethodCallExpression 呼び出し Average(IQueryable<Nullable<Double>>) 元自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average(IQueryable<Nullable<Double>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、 の source値の平均を計算することです。

適用対象

Average(IQueryable<Nullable<Single>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

Null 許容型の Single 値のシーケンスの平均を計算します。

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<float> Average(System::Linq::IQueryable<Nullable<float>> ^ source);
public static float? Average (this System.Linq.IQueryable<float?> source);
static member Average : System.Linq.IQueryable<Nullable<single>> -> Nullable<single>
<Extension()>
Public Function Average (source As IQueryable(Of Nullable(Of Single))) As Nullable(Of Single)

パラメーター

source
IQueryable<Nullable<Single>>

平均を計算する Null 許容型の Single 値のシーケンス。

戻り値

値のシーケンスの平均値、または、ソース シーケンスが空または null である値のみを含む場合は null

例外

sourcenullです。

次のコード例では、 を使用 Average(IQueryable<Nullable<Int64>>) して一連の値の平均を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この例をこの記事で説明するオーバーロードに拡張するには、ソース シーケンスの要素を適切な数値型の要素に置き換える必要があります。

long?[] longs = { null, 10007L, 37L, 399846234235L };

double? average = longs.AsQueryable().Average();

Console.WriteLine("The average is {0}.", average);

// This code produces the following output:
//
// The average is 133282081426.333.
Dim longs() As Nullable(Of Long) = {Nothing, 10007L, 37L, 399846234235L}

Dim average As Nullable(Of Double) = longs.AsQueryable().Average()

MsgBox(String.Format("The average is {0}.", average))

' This code produces the following output:
'
' The average is 133282081426.333.

注釈

メソッドは Average(IQueryable<Nullable<Single>>)MethodCallExpression 呼び出し Average(IQueryable<Nullable<Single>>) 元自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average(IQueryable<Nullable<Single>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、 の source値の平均を計算することです。

適用対象

Average(IQueryable<Int64>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

Int64 値のシーケンスの平均値を計算します。

public:
[System::Runtime::CompilerServices::Extension]
 static double Average(System::Linq::IQueryable<long> ^ source);
public static double Average (this System.Linq.IQueryable<long> source);
static member Average : System.Linq.IQueryable<int64> -> double
<Extension()>
Public Function Average (source As IQueryable(Of Long)) As Double

パラメーター

source
IQueryable<Int64>

平均値計算の対象となる Int64 値のシーケンス。

戻り値

値のシーケンスの平均値。

例外

sourcenullです。

source に要素が含まれていません。

次のコード例では、 を使用 Average(IQueryable<Int32>) して値のシーケンスの平均を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この記事で説明するオーバーロードに例を拡張するには、ソース シーケンスの要素を適切な数値型の要素に置き換えます。

List<int> grades = new List<int> { 78, 92, 100, 37, 81 };

double average = grades.AsQueryable().Average();

Console.WriteLine("The average grade is {0}.", average);

// This code produces the following output:
//
// The average grade is 77.6.
Dim grades As New List(Of Integer)(New Integer() {78, 92, 100, 37, 81})

Dim average As Double = grades.AsQueryable().Average()

MsgBox(String.Format("The average grade is {0}.", average))

' This code produces the following output:
'
' The average grade is 77.6.

注釈

メソッドはAverage(IQueryable<Int64>)、呼び出しAverage(IQueryable<Int64>)自体をMethodCallExpression表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average(IQueryable<Int64>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予期される動作は、 の source値の平均を計算することです。

適用対象

Average(IQueryable<Int32>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

Int32 値のシーケンスの平均値を計算します。

public:
[System::Runtime::CompilerServices::Extension]
 static double Average(System::Linq::IQueryable<int> ^ source);
public static double Average (this System.Linq.IQueryable<int> source);
static member Average : System.Linq.IQueryable<int> -> double
<Extension()>
Public Function Average (source As IQueryable(Of Integer)) As Double

パラメーター

source
IQueryable<Int32>

平均値計算の対象となる Int32 値のシーケンス。

戻り値

値のシーケンスの平均値。

例外

sourcenullです。

source に要素が含まれていません。

次のコード例では、 を使用 Average(IQueryable<Int32>) して値のシーケンスの平均を計算する方法を示します。

List<int> grades = new List<int> { 78, 92, 100, 37, 81 };

double average = grades.AsQueryable().Average();

Console.WriteLine("The average grade is {0}.", average);

// This code produces the following output:
//
// The average grade is 77.6.
Dim grades As New List(Of Integer)(New Integer() {78, 92, 100, 37, 81})

Dim average As Double = grades.AsQueryable().Average()

MsgBox(String.Format("The average grade is {0}.", average))

' This code produces the following output:
'
' The average grade is 77.6.

注釈

メソッドはAverage(IQueryable<Int32>)、呼び出しAverage(IQueryable<Int32>)自体をMethodCallExpression表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average(IQueryable<Int32>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予期される動作は、 の source値の平均を計算することです。

適用対象

Average(IQueryable<Double>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

Double 値のシーケンスの平均値を計算します。

public:
[System::Runtime::CompilerServices::Extension]
 static double Average(System::Linq::IQueryable<double> ^ source);
public static double Average (this System.Linq.IQueryable<double> source);
static member Average : System.Linq.IQueryable<double> -> double
<Extension()>
Public Function Average (source As IQueryable(Of Double)) As Double

パラメーター

source
IQueryable<Double>

平均値計算の対象となる Double 値のシーケンス。

戻り値

値のシーケンスの平均値。

例外

sourcenullです。

source に要素が含まれていません。

次のコード例では、 を使用 Average(IQueryable<Int32>) して値のシーケンスの平均を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この記事で説明するオーバーロードに例を拡張するには、ソース シーケンスの要素を適切な数値型の要素に置き換えます。

List<int> grades = new List<int> { 78, 92, 100, 37, 81 };

double average = grades.AsQueryable().Average();

Console.WriteLine("The average grade is {0}.", average);

// This code produces the following output:
//
// The average grade is 77.6.
Dim grades As New List(Of Integer)(New Integer() {78, 92, 100, 37, 81})

Dim average As Double = grades.AsQueryable().Average()

MsgBox(String.Format("The average grade is {0}.", average))

' This code produces the following output:
'
' The average grade is 77.6.

注釈

メソッドはAverage(IQueryable<Double>)、呼び出しAverage(IQueryable<Double>)自体をMethodCallExpression表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average(IQueryable<Double>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予期される動作は、 の source値の平均を計算することです。

適用対象

Average(IQueryable<Decimal>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

Decimal 値のシーケンスの平均値を計算します。

public:
[System::Runtime::CompilerServices::Extension]
 static System::Decimal Average(System::Linq::IQueryable<System::Decimal> ^ source);
public static decimal Average (this System.Linq.IQueryable<decimal> source);
static member Average : System.Linq.IQueryable<decimal> -> decimal
<Extension()>
Public Function Average (source As IQueryable(Of Decimal)) As Decimal

パラメーター

source
IQueryable<Decimal>

平均値計算の対象となる Decimal 値のシーケンス。

戻り値

値のシーケンスの平均値。

例外

sourcenullです。

source に要素が含まれていません。

次のコード例では、 を使用 Average(IQueryable<Int32>) して値のシーケンスの平均を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この記事で説明するオーバーロードに例を拡張するには、ソース シーケンスの要素を適切な数値型の要素に置き換えます。

List<int> grades = new List<int> { 78, 92, 100, 37, 81 };

double average = grades.AsQueryable().Average();

Console.WriteLine("The average grade is {0}.", average);

// This code produces the following output:
//
// The average grade is 77.6.
Dim grades As New List(Of Integer)(New Integer() {78, 92, 100, 37, 81})

Dim average As Double = grades.AsQueryable().Average()

MsgBox(String.Format("The average grade is {0}.", average))

' This code produces the following output:
'
' The average grade is 77.6.

注釈

メソッドはAverage(IQueryable<Decimal>)、呼び出しAverage(IQueryable<Decimal>)自体をMethodCallExpression表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average(IQueryable<Decimal>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予期される動作は、 の source値の平均を計算することです。

適用対象

Average(IQueryable<Nullable<Decimal>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

Null 許容型の Decimal 値のシーケンスの平均を計算します。

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<System::Decimal> Average(System::Linq::IQueryable<Nullable<System::Decimal>> ^ source);
public static decimal? Average (this System.Linq.IQueryable<decimal?> source);
static member Average : System.Linq.IQueryable<Nullable<decimal>> -> Nullable<decimal>
<Extension()>
Public Function Average (source As IQueryable(Of Nullable(Of Decimal))) As Nullable(Of Decimal)

パラメーター

source
IQueryable<Nullable<Decimal>>

平均を計算する Null 許容型の Decimal 値のシーケンス。

戻り値

値のシーケンスの平均値、または、ソース シーケンスが空または null である値のみを含む場合は null

例外

sourcenullです。

次のコード例では、 を使用 Average(IQueryable<Nullable<Int64>>) して値のシーケンスの平均を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この記事で説明するオーバーロードに例を拡張するには、ソース シーケンスの要素を適切な数値型の要素に置き換えます。

long?[] longs = { null, 10007L, 37L, 399846234235L };

double? average = longs.AsQueryable().Average();

Console.WriteLine("The average is {0}.", average);

// This code produces the following output:
//
// The average is 133282081426.333.
Dim longs() As Nullable(Of Long) = {Nothing, 10007L, 37L, 399846234235L}

Dim average As Nullable(Of Double) = longs.AsQueryable().Average()

MsgBox(String.Format("The average is {0}.", average))

' This code produces the following output:
'
' The average is 133282081426.333.

注釈

メソッドはAverage(IQueryable<Nullable<Decimal>>)、呼び出しAverage(IQueryable<Nullable<Decimal>>)自体をMethodCallExpression表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average(IQueryable<Nullable<Decimal>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予期される動作は、 の source値の平均を計算することです。

適用対象

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

入力シーケンスの各要素に対して射影関数を呼び出して取得する Single 値のシーケンスの平均値を計算します。

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

型パラメーター

TSource

source の要素の型。

パラメーター

source
IQueryable<TSource>

平均値計算の対象となる値のシーケンス。

selector
Expression<Func<TSource,Single>>

各要素に適用する射影関数。

戻り値

値のシーケンスの平均値。

例外

source または selectornull です。

source に要素が含まれていません。

次のコード例では、 を使用Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)して、 型Stringの値のシーケンスで平均String長を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この記事で説明するオーバーロードに例を拡張するには、 関数の本体を変更します selector

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

// Determine the average string length in the array.
double average = fruits.AsQueryable().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.
Dim fruits() As String = {"apple", "banana", "mango", "orange", "passionfruit", "grape"}

' Determine the average string length in the array.
Dim average As Double = fruits.AsQueryable().Average(Function(s) s.Length)

MsgBox(String.Format("The average string length is {0}.", average))

' This code produces the following output:
'
' The average string length is 6.5.

注釈

このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターでは、ラムダ式を渡すことができます。これは に Expression<TDelegate>コンパイルされます。

メソッドは Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>)MethodCallExpression 構築されたジェネリック メソッドとして自身を呼び出すことを Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>) 表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、各値で を呼び出した後に の source 値の平均を selector 計算することです。

適用対象

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

入力シーケンスの各要素に対して射影関数を呼び出して取得する、null 許容の Single 値のシーケンスの平均値を計算します。

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

型パラメーター

TSource

source の要素の型。

パラメーター

source
IQueryable<TSource>

平均値計算の対象となる値のシーケンス。

selector
Expression<Func<TSource,Nullable<Single>>>

各要素に適用する射影関数。

戻り値

値のシーケンスの平均値。source シーケンスが空か null 値のみを含む場合は null

例外

source または selectornull です。

次のコード例では、 を使用Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)して、 型Stringの値のシーケンスで平均String長を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この記事で説明するオーバーロードに例を拡張するには、 関数の本体を変更します selector

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

// Determine the average string length in the array.
double average = fruits.AsQueryable().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.
Dim fruits() As String = {"apple", "banana", "mango", "orange", "passionfruit", "grape"}

' Determine the average string length in the array.
Dim average As Double = fruits.AsQueryable().Average(Function(s) s.Length)

MsgBox(String.Format("The average string length is {0}.", average))

' This code produces the following output:
'
' The average string length is 6.5.

注釈

このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターでは、ラムダ式を渡すことができます。これは に Expression<TDelegate>コンパイルされます。

メソッドは Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>)MethodCallExpression 構築されたジェネリック メソッドとして自身を呼び出すことを Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>) 表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティでProvider表される の IQueryProvider メソッドに をsource渡します。

呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、各値で を呼び出した後に の source 値の平均を selector 計算することです。

適用対象

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

入力シーケンスの各要素に対して射影関数を呼び出して取得する、null 許容の Int64 値のシーケンスの平均値を計算します。

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<double> Average(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, Nullable<long>> ^> ^ selector);
public static double? Average<TSource> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,long?>> selector);
static member Average : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, Nullable<int64>>> -> Nullable<double>
<Extension()>
Public Function Average(Of TSource) (source As IQueryable(Of TSource), selector As Expression(Of Func(Of TSource, Nullable(Of Long)))) As Nullable(Of Double)

型パラメーター

TSource

source の要素の型。

パラメーター

source
IQueryable<TSource>

平均値計算の対象となる値のシーケンス。

selector
Expression<Func<TSource,Nullable<Int64>>>

各要素に適用する射影関数。

戻り値

値のシーケンスの平均値。source シーケンスが空か null 値のみを含む場合は null

例外

source または selectornull です。

次のコード例では、 を使用Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)して、 型Stringの値のシーケンスで平均String長を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この記事で説明するオーバーロードに例を拡張するには、 関数の本体を変更します selector

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

// Determine the average string length in the array.
double average = fruits.AsQueryable().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.
Dim fruits() As String = {"apple", "banana", "mango", "orange", "passionfruit", "grape"}

' Determine the average string length in the array.
Dim average As Double = fruits.AsQueryable().Average(Function(s) s.Length)

MsgBox(String.Format("The average string length is {0}.", average))

' This code produces the following output:
'
' The average string length is 6.5.

注釈

このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターでは、ラムダ式を渡すと、 に Expression<TDelegate>コンパイルされます。

メソッドは Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>)MethodCallExpression 構築されたジェネリック メソッドとしての呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>) 自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、各値を呼び出した後に の source 値の平均を selector 計算することです。

適用対象

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

入力シーケンスの各要素に対して射影関数を呼び出して取得する、null 許容の Double 値のシーケンスの平均値を計算します。

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

型パラメーター

TSource

source の要素の型。

パラメーター

source
IQueryable<TSource>

平均値計算の対象となる値のシーケンス。

selector
Expression<Func<TSource,Nullable<Double>>>

各要素に適用する射影関数。

戻り値

値のシーケンスの平均値。source シーケンスが空か null 値のみを含む場合は null

例外

source または selectornull です。

次のコード例では、 を使用Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)して、 型Stringの値のシーケンスの平均String長を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この例をこの記事で説明するオーバーロードに拡張するには、関数の本体を変更します selector

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

// Determine the average string length in the array.
double average = fruits.AsQueryable().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.
Dim fruits() As String = {"apple", "banana", "mango", "orange", "passionfruit", "grape"}

' Determine the average string length in the array.
Dim average As Double = fruits.AsQueryable().Average(Function(s) s.Length)

MsgBox(String.Format("The average string length is {0}.", average))

' This code produces the following output:
'
' The average string length is 6.5.

注釈

このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターでは、ラムダ式を渡すと、 に Expression<TDelegate>コンパイルされます。

メソッドは Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>)MethodCallExpression 構築されたジェネリック メソッドとしての呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>) 自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、各値を呼び出した後に の source 値の平均を selector 計算することです。

適用対象

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

入力シーケンスの各要素に対して射影関数を呼び出して取得する、null 許容の Int32 値のシーケンスの平均値を計算します。

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<double> Average(System::Linq::IQueryable<TSource> ^ source, System::Linq::Expressions::Expression<Func<TSource, Nullable<int>> ^> ^ selector);
public static double? Average<TSource> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,int?>> selector);
static member Average : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, Nullable<int>>> -> Nullable<double>
<Extension()>
Public Function Average(Of TSource) (source As IQueryable(Of TSource), selector As Expression(Of Func(Of TSource, Nullable(Of Integer)))) As Nullable(Of Double)

型パラメーター

TSource

source の要素の型。

パラメーター

source
IQueryable<TSource>

平均値計算の対象となる値のシーケンス。

selector
Expression<Func<TSource,Nullable<Int32>>>

各要素に適用する射影関数。

戻り値

値のシーケンスの平均値。source シーケンスが空か null 値のみを含む場合は null

例外

source または selectornull です。

次のコード例では、 を使用Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)して、 型Stringの値のシーケンスの平均String長を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この例をこの記事で説明するオーバーロードに拡張するには、関数の本体を変更します selector

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

// Determine the average string length in the array.
double average = fruits.AsQueryable().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.
Dim fruits() As String = {"apple", "banana", "mango", "orange", "passionfruit", "grape"}

' Determine the average string length in the array.
Dim average As Double = fruits.AsQueryable().Average(Function(s) s.Length)

MsgBox(String.Format("The average string length is {0}.", average))

' This code produces the following output:
'
' The average string length is 6.5.

注釈

このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターでは、ラムダ式を渡すと、 に Expression<TDelegate>コンパイルされます。

メソッドは Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>)MethodCallExpression 構築されたジェネリック メソッドとしての呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>) 自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティでProvider表される の IQueryProvider メソッドに をsource渡します。

呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、各値を呼び出した後に の source 値の平均を selector 計算することです。

適用対象

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

入力シーケンスの各要素に対して射影関数を呼び出して取得する Int64 値のシーケンスの平均値を計算します。

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

型パラメーター

TSource

source の要素の型。

パラメーター

source
IQueryable<TSource>

平均値計算の対象となる値のシーケンス。

selector
Expression<Func<TSource,Int64>>

各要素に適用する射影関数。

戻り値

値のシーケンスの平均値。

例外

source または selectornull です。

source に要素が含まれていません。

次のコード例では、 を使用Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)して、 型Stringの値のシーケンスの平均String長を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この例をこの記事で説明するオーバーロードに拡張するには、関数の本体を変更します selector

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

// Determine the average string length in the array.
double average = fruits.AsQueryable().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.
Dim fruits() As String = {"apple", "banana", "mango", "orange", "passionfruit", "grape"}

' Determine the average string length in the array.
Dim average As Double = fruits.AsQueryable().Average(Function(s) s.Length)

MsgBox(String.Format("The average string length is {0}.", average))

' This code produces the following output:
'
' The average string length is 6.5.

注釈

このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターでは、ラムダ式を渡すと、 に Expression<TDelegate>コンパイルされます。

メソッドは Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>)MethodCallExpression 構築されたジェネリック メソッドとしての呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>) 自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、各値を呼び出した後に の source 値の平均を selector 計算することです。

適用対象

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

入力シーケンスの各要素に対して射影関数を呼び出して取得する Int32 値のシーケンスの平均値を計算します。

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

型パラメーター

TSource

source の要素の型。

パラメーター

source
IQueryable<TSource>

平均値計算の対象となる値のシーケンス。

selector
Expression<Func<TSource,Int32>>

各要素に適用する射影関数。

戻り値

値のシーケンスの平均値。

例外

source または selectornull です。

source に要素が含まれていません。

次のコード例では、 を使用Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)して、 型Stringの値のシーケンスの平均String長を計算する方法を示します。

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

// Determine the average string length in the array.
double average = fruits.AsQueryable().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.
Dim fruits() As String = {"apple", "banana", "mango", "orange", "passionfruit", "grape"}

' Determine the average string length in the array.
Dim average As Double = fruits.AsQueryable().Average(Function(s) s.Length)

MsgBox(String.Format("The average string length is {0}.", average))

' This code produces the following output:
'
' The average string length is 6.5.

注釈

このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターでは、ラムダ式を渡すと、 に Expression<TDelegate>コンパイルされます。

メソッドは Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)MethodCallExpression 構築されたジェネリック メソッドとしての呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) 自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、各値を呼び出した後に の source 値の平均を selector 計算することです。

適用対象

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

入力シーケンスの各要素に対して射影関数を呼び出して取得する Double 値のシーケンスの平均値を計算します。

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

型パラメーター

TSource

source の要素の型。

パラメーター

source
IQueryable<TSource>

平均値計算の対象となる値のシーケンス。

selector
Expression<Func<TSource,Double>>

各要素に適用する射影関数。

戻り値

値のシーケンスの平均値。

例外

source または selectornull です。

source に要素が含まれていません。

次のコード例では、 を使用Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)して、 型Stringの値のシーケンスの平均String長を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この例をこの記事で説明するオーバーロードに拡張するには、関数の本体を変更します selector

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

// Determine the average string length in the array.
double average = fruits.AsQueryable().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.
Dim fruits() As String = {"apple", "banana", "mango", "orange", "passionfruit", "grape"}

' Determine the average string length in the array.
Dim average As Double = fruits.AsQueryable().Average(Function(s) s.Length)

MsgBox(String.Format("The average string length is {0}.", average))

' This code produces the following output:
'
' The average string length is 6.5.

注釈

このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターでは、ラムダ式を渡すと、 に Expression<TDelegate>コンパイルされます。

メソッドは Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>)MethodCallExpression 構築されたジェネリック メソッドとしての呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>) 自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、各値を呼び出した後に の source 値の平均を selector 計算することです。

適用対象

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

入力シーケンスの各要素に対して射影関数を呼び出して取得する Decimal 値のシーケンスの平均値を計算します。

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

型パラメーター

TSource

source の要素の型。

パラメーター

source
IQueryable<TSource>

平均値の計算に使用される値のシーケンス。

selector
Expression<Func<TSource,Decimal>>

各要素に適用する射影関数。

戻り値

値のシーケンスの平均値。

例外

source または selectornull です。

source に要素が含まれていません。

次のコード例では、 を使用Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)して、 型Stringの値のシーケンスの平均String長を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この例をこの記事で説明するオーバーロードに拡張するには、関数の本体を変更します selector

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

// Determine the average string length in the array.
double average = fruits.AsQueryable().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.
Dim fruits() As String = {"apple", "banana", "mango", "orange", "passionfruit", "grape"}

' Determine the average string length in the array.
Dim average As Double = fruits.AsQueryable().Average(Function(s) s.Length)

MsgBox(String.Format("The average string length is {0}.", average))

' This code produces the following output:
'
' The average string length is 6.5.

注釈

このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターでは、ラムダ式を渡すと、 に Expression<TDelegate>コンパイルされます。

メソッドは Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>)MethodCallExpression 構築されたジェネリック メソッドとしての呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>) 自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、各値を呼び出した後に の source 値の平均を selector 計算することです。

適用対象

Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>)

ソース:
Queryable.cs
ソース:
Queryable.cs
ソース:
Queryable.cs

入力シーケンスの各要素に対して射影関数を呼び出して取得する、null 許容の Decimal 値のシーケンスの平均値を計算します。

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

型パラメーター

TSource

source の要素の型。

パラメーター

source
IQueryable<TSource>

平均値計算の対象となる値のシーケンス。

selector
Expression<Func<TSource,Nullable<Decimal>>>

各要素に適用する射影関数。

戻り値

値のシーケンスの平均値。source シーケンスが空か null 値のみを含む場合は null

例外

source または selectornull です。

次のコード例では、 を使用Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)して、 型Stringの値のシーケンスの平均String長を計算する方法を示します。

注意

このコード例では、この記事で説明する特定のオーバーロードとは異なる メソッドのオーバーロードを使用します。 この例をこの記事で説明するオーバーロードに拡張するには、関数の本体を変更します selector

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

// Determine the average string length in the array.
double average = fruits.AsQueryable().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.
Dim fruits() As String = {"apple", "banana", "mango", "orange", "passionfruit", "grape"}

' Determine the average string length in the array.
Dim average As Double = fruits.AsQueryable().Average(Function(s) s.Length)

MsgBox(String.Format("The average string length is {0}.", average))

' This code produces the following output:
'
' The average string length is 6.5.

注釈

このメソッドには、型引数が型 Expression<TDelegate> の 1 つである型のパラメーターが少なくとも 1 つ Func<T,TResult> 含まれています。 これらのパラメーターでは、ラムダ式を渡すと、 に Expression<TDelegate>コンパイルされます。

メソッドは Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>)MethodCallExpression 構築されたジェネリック メソッドとしての呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>) 自体を表す を生成します。 次に、 パラメーターの MethodCallExpressionExecute<TResult>(Expression) プロパティで表される の IQueryProvider メソッドに をProvidersource渡します。

呼び出し Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>) を表す式ツリーを実行した結果として発生するクエリ動作は、 パラメーターの型の source 実装によって異なります。 予想される動作は、各値を呼び出した後に の source 値の平均を selector 計算することです。

適用対象