Queryable.Average Método
Definición
Calcula el promedio de una secuencia de valores numéricos.Computes the average of a sequence of numeric values.
Sobrecargas
Average(IQueryable<Single>) |
Calcula el promedio de una secuencia de valores Single.Computes the average of a sequence of Single values. |
Average(IQueryable<Nullable<Single>>) |
Calcula el promedio de una secuencia de valores Single que admiten valores NULL.Computes the average of a sequence of nullable Single values. |
Average(IQueryable<Nullable<Int64>>) |
Calcula el promedio de una secuencia de valores Int64 que admiten valores NULL.Computes the average of a sequence of nullable Int64 values. |
Average(IQueryable<Nullable<Double>>) |
Calcula el promedio de una secuencia de valores Double que admiten valores NULL.Computes the average of a sequence of nullable Double values. |
Average(IQueryable<Nullable<Int32>>) |
Calcula el promedio de una secuencia de valores Int32 que admiten valores NULL.Computes the average of a sequence of nullable Int32 values. |
Average(IQueryable<Int64>) |
Calcula el promedio de una secuencia de valores Int64.Computes the average of a sequence of Int64 values. |
Average(IQueryable<Int32>) |
Calcula el promedio de una secuencia de valores Int32.Computes the average of a sequence of Int32 values. |
Average(IQueryable<Double>) |
Calcula el promedio de una secuencia de valores Double.Computes the average of a sequence of Double values. |
Average(IQueryable<Decimal>) |
Calcula el promedio de una secuencia de valores Decimal.Computes the average of a sequence of Decimal values. |
Average(IQueryable<Nullable<Decimal>>) |
Calcula el promedio de una secuencia de valores Decimal que admiten valores NULL.Computes the average of a sequence of nullable Decimal values. |
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>) |
Calcula el promedio de una secuencia de valores Single que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of Single values that is obtained by invoking a projection function on each element of the input sequence. |
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>) |
Calcula el promedio de una secuencia de valores Single que aceptan valores NULL que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of nullable Single values that is obtained by invoking a projection function on each element of the input sequence. |
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>) |
Calcula el promedio de una secuencia de valores Int64 que aceptan valores NULL que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of nullable Int64 values that is obtained by invoking a projection function on each element of the input sequence. |
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>) |
Calcula el promedio de una secuencia de valores Int32 que aceptan valores NULL que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of nullable Int32 values that is obtained by invoking a projection function on each element of the input sequence. |
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>) |
Calcula el promedio de una secuencia de valores Double que aceptan valores NULL que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of nullable Double values that is obtained by invoking a projection function on each element of the input sequence. |
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>) |
Calcula el promedio de una secuencia de valores Int64 que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of Int64 values that is obtained by invoking a projection function on each element of the input sequence. |
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) |
Calcula el promedio de una secuencia de valores Int32 que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of Int32 values that is obtained by invoking a projection function on each element of the input sequence. |
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>) |
Calcula el promedio de una secuencia de valores Double que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of Double values that is obtained by invoking a projection function on each element of the input sequence. |
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>) |
Calcula el promedio de una secuencia de valores Decimal que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of Decimal values that is obtained by invoking a projection function on each element of the input sequence. |
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>) |
Calcula el promedio de una secuencia de valores Decimal que aceptan valores NULL que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of nullable Decimal values that is obtained by invoking a projection function on each element of the input sequence. |
Average(IQueryable<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
Parámetros
- source
- IQueryable<Single>
Secuencia de valores Single cuyo promedio se va a calcular.A sequence of Single values to calculate the average of.
Devoluciones
El promedio de la secuencia de valores.The average of the sequence of values.
Excepciones
source
es null
.source
is null
.
source
no contiene ningún elemento.source
contains no elements.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar Average(IQueryable<Int32>) para calcular el promedio de una secuencia de valores.The following code example demonstrates how to use Average(IQueryable<Int32>) to calculate the average of a sequence of values.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, sustituye los elementos de la secuencia de origen por los elementos del tipo numérico adecuado.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.
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.
Comentarios
El Average(IQueryable<Single>) método genera un MethodCallExpression que representa la llamada a Average(IQueryable<Single>) sí mismo.The Average(IQueryable<Single>) method generates a MethodCallExpression that represents calling Average(IQueryable<Single>) itself. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average(IQueryable<Single>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average(IQueryable<Single>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de source
.The expected behavior is that it calculates the average of the values in source
.
Se aplica a
Average(IQueryable<Nullable<Single>>)
public:
[System::Runtime::CompilerServices::Extension]
static Nullable<float> Average(System::Linq::IQueryable<Nullable<float>> ^ source);
public static float? Average (this System.Linq.IQueryable<Nullable<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)
Parámetros
- source
- IQueryable<Nullable<Single>>
Secuencia de valores Single que admiten valores NULL para calcular el promedio.A sequence of nullable Single values to calculate the average of.
Devoluciones
Promedio de la secuencia de valores o null
si la secuencia de origen está vacía o contiene solo valores null
.The average of the sequence of values, or null
if the source sequence is empty or contains only null
values.
Excepciones
source
es null
.source
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar Average(IQueryable<Nullable<Int64>>) para calcular el promedio de una secuencia de valores.The following code example demonstrates how to use Average(IQueryable<Nullable<Int64>>) to calculate the average of a sequence of values.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, sustituye los elementos de la secuencia de origen por los elementos del tipo numérico adecuado.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.
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.
Comentarios
El Average(IQueryable<Nullable<Single>>) método genera un MethodCallExpression que representa la llamada a Average(IQueryable<Nullable<Single>>) sí mismo.The Average(IQueryable<Nullable<Single>>) method generates a MethodCallExpression that represents calling Average(IQueryable<Nullable<Single>>) itself. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average(IQueryable<Nullable<Single>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average(IQueryable<Nullable<Single>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de source
.The expected behavior is that it calculates the average of the values in source
.
Se aplica a
Average(IQueryable<Nullable<Int64>>)
public:
[System::Runtime::CompilerServices::Extension]
static Nullable<double> Average(System::Linq::IQueryable<Nullable<long>> ^ source);
public static double? Average (this System.Linq.IQueryable<Nullable<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)
Parámetros
- source
- IQueryable<Nullable<Int64>>
Secuencia de valores Int64 que admiten valores NULL para calcular el promedio.A sequence of nullable Int64 values to calculate the average of.
Devoluciones
Promedio de la secuencia de valores o null
si la secuencia de origen está vacía o contiene solo valores null
.The average of the sequence of values, or null
if the source sequence is empty or contains only null
values.
Excepciones
source
es null
.source
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar Average(IQueryable<Nullable<Int64>>) para calcular el promedio de una secuencia de valores.The following code example demonstrates how to use Average(IQueryable<Nullable<Int64>>) to calculate the average of a sequence of values.
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.
Comentarios
El Average(IQueryable<Nullable<Int64>>) método genera un MethodCallExpression que representa la llamada a Average(IQueryable<Nullable<Int64>>) sí mismo.The Average(IQueryable<Nullable<Int64>>) method generates a MethodCallExpression that represents calling Average(IQueryable<Nullable<Int64>>) itself. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average(IQueryable<Nullable<Int64>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average(IQueryable<Nullable<Int64>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de source
.The expected behavior is that it calculates the average of the values in source
.
Se aplica a
Average(IQueryable<Nullable<Double>>)
public:
[System::Runtime::CompilerServices::Extension]
static Nullable<double> Average(System::Linq::IQueryable<Nullable<double>> ^ source);
public static double? Average (this System.Linq.IQueryable<Nullable<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)
Parámetros
- source
- IQueryable<Nullable<Double>>
Secuencia de valores Double que admiten valores NULL para calcular el promedio.A sequence of nullable Double values to calculate the average of.
Devoluciones
Promedio de la secuencia de valores o null
si la secuencia de origen está vacía o contiene solo valores null
.The average of the sequence of values, or null
if the source sequence is empty or contains only null
values.
Excepciones
source
es null
.source
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar Average(IQueryable<Nullable<Int64>>) para calcular el promedio de una secuencia de valores.The following code example demonstrates how to use Average(IQueryable<Nullable<Int64>>) to calculate the average of a sequence of values.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, sustituye los elementos de la secuencia de origen por los elementos del tipo numérico adecuado.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.
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.
Comentarios
El Average(IQueryable<Nullable<Double>>) método genera un MethodCallExpression que representa la llamada a Average(IQueryable<Nullable<Double>>) sí mismo.The Average(IQueryable<Nullable<Double>>) method generates a MethodCallExpression that represents calling Average(IQueryable<Nullable<Double>>) itself. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average(IQueryable<Nullable<Double>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average(IQueryable<Nullable<Double>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de source
.The expected behavior is that it calculates the average of the values in source
.
Se aplica a
Average(IQueryable<Nullable<Int32>>)
public:
[System::Runtime::CompilerServices::Extension]
static Nullable<double> Average(System::Linq::IQueryable<Nullable<int>> ^ source);
public static double? Average (this System.Linq.IQueryable<Nullable<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)
Parámetros
- source
- IQueryable<Nullable<Int32>>
Secuencia de valores Int32 que admiten valores NULL para calcular el promedio.A sequence of nullable Int32 values to calculate the average of.
Devoluciones
Promedio de la secuencia de valores o null
si la secuencia de origen está vacía o contiene solo valores null
.The average of the sequence of values, or null
if the source sequence is empty or contains only null
values.
Excepciones
source
es null
.source
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar Average(IQueryable<Nullable<Int64>>) para calcular el promedio de una secuencia de valores.The following code example demonstrates how to use Average(IQueryable<Nullable<Int64>>) to calculate the average of a sequence of values.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, sustituye los elementos de la secuencia de origen por los elementos del tipo numérico adecuado.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.
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.
Comentarios
El Average(IQueryable<Nullable<Int32>>) método genera un MethodCallExpression que representa la llamada a Average(IQueryable<Nullable<Int32>>) sí mismo.The Average(IQueryable<Nullable<Int32>>) method generates a MethodCallExpression that represents calling Average(IQueryable<Nullable<Int32>>) itself. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average(IQueryable<Nullable<Int32>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average(IQueryable<Nullable<Int32>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de source
.The expected behavior is that it calculates the average of the values in source
.
Se aplica a
Average(IQueryable<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
Parámetros
- source
- IQueryable<Int64>
Secuencia de valores Int64 cuyo promedio se va a calcular.A sequence of Int64 values to calculate the average of.
Devoluciones
El promedio de la secuencia de valores.The average of the sequence of values.
Excepciones
source
es null
.source
is null
.
source
no contiene ningún elemento.source
contains no elements.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar Average(IQueryable<Int32>) para calcular el promedio de una secuencia de valores.The following code example demonstrates how to use Average(IQueryable<Int32>) to calculate the average of a sequence of values.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, sustituye los elementos de la secuencia de origen por los elementos del tipo numérico adecuado.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.
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.
Comentarios
El Average(IQueryable<Int64>) método genera un MethodCallExpression que representa la llamada a Average(IQueryable<Int64>) sí mismo.The Average(IQueryable<Int64>) method generates a MethodCallExpression that represents calling Average(IQueryable<Int64>) itself. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average(IQueryable<Int64>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average(IQueryable<Int64>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de source
.The expected behavior is that it calculates the average of the values in source
.
Se aplica a
Average(IQueryable<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
Parámetros
- source
- IQueryable<Int32>
Secuencia de valores Int32 cuyo promedio se va a calcular.A sequence of Int32 values to calculate the average of.
Devoluciones
El promedio de la secuencia de valores.The average of the sequence of values.
Excepciones
source
es null
.source
is null
.
source
no contiene ningún elemento.source
contains no elements.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar Average(IQueryable<Int32>) para calcular el promedio de una secuencia de valores.The following code example demonstrates how to use Average(IQueryable<Int32>) to calculate the average of a sequence of values.
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.
Comentarios
El Average(IQueryable<Int32>) método genera un MethodCallExpression que representa la llamada a Average(IQueryable<Int32>) sí mismo.The Average(IQueryable<Int32>) method generates a MethodCallExpression that represents calling Average(IQueryable<Int32>) itself. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average(IQueryable<Int32>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average(IQueryable<Int32>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de source
.The expected behavior is that it calculates the average of the values in source
.
Se aplica a
Average(IQueryable<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
Parámetros
- source
- IQueryable<Double>
Secuencia de valores Double cuyo promedio se va a calcular.A sequence of Double values to calculate the average of.
Devoluciones
El promedio de la secuencia de valores.The average of the sequence of values.
Excepciones
source
es null
.source
is null
.
source
no contiene ningún elemento.source
contains no elements.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar Average(IQueryable<Int32>) para calcular el promedio de una secuencia de valores.The following code example demonstrates how to use Average(IQueryable<Int32>) to calculate the average of a sequence of values.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, sustituye los elementos de la secuencia de origen por los elementos del tipo numérico adecuado.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.
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.
Comentarios
El Average(IQueryable<Double>) método genera un MethodCallExpression que representa la llamada a Average(IQueryable<Double>) sí mismo.The Average(IQueryable<Double>) method generates a MethodCallExpression that represents calling Average(IQueryable<Double>) itself. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average(IQueryable<Double>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average(IQueryable<Double>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de source
.The expected behavior is that it calculates the average of the values in source
.
Se aplica a
Average(IQueryable<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
Parámetros
- source
- IQueryable<Decimal>
Secuencia de valores Decimal cuyo promedio se va a calcular.A sequence of Decimal values to calculate the average of.
Devoluciones
El promedio de la secuencia de valores.The average of the sequence of values.
Excepciones
source
es null
.source
is null
.
source
no contiene ningún elemento.source
contains no elements.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar Average(IQueryable<Int32>) para calcular el promedio de una secuencia de valores.The following code example demonstrates how to use Average(IQueryable<Int32>) to calculate the average of a sequence of values.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, sustituye los elementos de la secuencia de origen por los elementos del tipo numérico adecuado.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.
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.
Comentarios
El Average(IQueryable<Decimal>) método genera un MethodCallExpression que representa la llamada a Average(IQueryable<Decimal>) sí mismo.The Average(IQueryable<Decimal>) method generates a MethodCallExpression that represents calling Average(IQueryable<Decimal>) itself. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average(IQueryable<Decimal>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average(IQueryable<Decimal>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de source
.The expected behavior is that it calculates the average of the values in source
.
Se aplica a
Average(IQueryable<Nullable<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<Nullable<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)
Parámetros
- source
- IQueryable<Nullable<Decimal>>
Secuencia de valores Decimal que admiten valores NULL para calcular el promedio.A sequence of nullable Decimal values to calculate the average of.
Devoluciones
Promedio de la secuencia de valores o null
si la secuencia de origen está vacía o contiene solo valores null
.The average of the sequence of values, or null
if the source sequence is empty or contains only null
values.
Excepciones
source
es null
.source
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar Average(IQueryable<Nullable<Int64>>) para calcular el promedio de una secuencia de valores.The following code example demonstrates how to use Average(IQueryable<Nullable<Int64>>) to calculate the average of a sequence of values.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, sustituye los elementos de la secuencia de origen por los elementos del tipo numérico adecuado.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.
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.
Comentarios
El Average(IQueryable<Nullable<Decimal>>) método genera un MethodCallExpression que representa la llamada a Average(IQueryable<Nullable<Decimal>>) sí mismo.The Average(IQueryable<Nullable<Decimal>>) method generates a MethodCallExpression that represents calling Average(IQueryable<Nullable<Decimal>>) itself. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average(IQueryable<Nullable<Decimal>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average(IQueryable<Nullable<Decimal>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de source
.The expected behavior is that it calculates the average of the values in source
.
Se aplica a
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,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
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
Parámetros
- source
- IQueryable<TSource>
Una secuencia de valores de la que se calculará el promedio.A sequence of values to calculate the average of.
- selector
- Expression<Func<TSource,Single>>
Función de proyección que se va a aplicar a cada elemento.A projection function to apply to each element.
Devoluciones
El promedio de la secuencia de valores.The average of the sequence of values.
Excepciones
source
o selector
es null
.source
or selector
is null
.
source
no contiene ningún elemento.source
contains no elements.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) para calcular la String longitud media en una secuencia de valores de tipo String .The following code example demonstrates how to use Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) to calculate the average String length in a sequence of values of type String.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, cambie el cuerpo de la función selector
.To extend the example to this topic, change the body of the selector
function.
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.
Comentarios
Este método tiene al menos un parámetro de tipo Expression<TDelegate> cuyo argumento de tipo es uno de los Func<T,TResult> tipos.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Para estos parámetros, puede pasar una expresión lambda y se compilará en un Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.
El Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>) método genera un MethodCallExpression que representa la llamada a Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>) sí mismo como un método genérico construido.The Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>) method generates a MethodCallExpression that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de después de source
invocar selector
en cada valor.The expected behavior is that it calculates the average of the values in source
after invoking selector
on each value.
Se aplica a
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>)
Calcula el promedio de una secuencia de valores Single que aceptan valores NULL que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of nullable Single values that is obtained by invoking a projection function on each element of the input sequence.
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,Nullable<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)
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
Parámetros
- source
- IQueryable<TSource>
Una secuencia de valores de la que se calculará el promedio.A sequence of values to calculate the average of.
- selector
- Expression<Func<TSource,Nullable<Single>>>
Función de proyección que se va a aplicar a cada elemento.A projection function to apply to each element.
Devoluciones
Promedio de la secuencia de valores o null
si la secuencia source
está vacía o contiene solo valores null
.The average of the sequence of values, or null
if the source
sequence is empty or contains only null
values.
Excepciones
source
o selector
es null
.source
or selector
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) para calcular la String longitud media en una secuencia de valores de tipo String .The following code example demonstrates how to use Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) to calculate the average String length in a sequence of values of type String.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, cambie el cuerpo de la función selector
.To extend the example to this topic, change the body of the selector
function.
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.
Comentarios
Este método tiene al menos un parámetro de tipo Expression<TDelegate> cuyo argumento de tipo es uno de los Func<T,TResult> tipos.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Para estos parámetros, puede pasar una expresión lambda y se compilará en un Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.
El Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>) método genera un MethodCallExpression que representa la llamada a Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>) sí mismo como un método genérico construido.The Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>) method generates a MethodCallExpression that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de la IQueryProvider propiedad representada por Provider del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de después de source
invocar selector
en cada valor.The expected behavior is that it calculates the average of the values in source
after invoking selector
on each value.
Se aplica a
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>)
Calcula el promedio de una secuencia de valores Int64 que aceptan valores NULL que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of nullable Int64 values that is obtained by invoking a projection function on each element of the input sequence.
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,Nullable<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)
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
Parámetros
- source
- IQueryable<TSource>
Una secuencia de valores de la que se calculará el promedio.A sequence of values to calculate the average of.
- selector
- Expression<Func<TSource,Nullable<Int64>>>
Función de proyección que se va a aplicar a cada elemento.A projection function to apply to each element.
Devoluciones
Promedio de la secuencia de valores o null
si la secuencia source
está vacía o contiene solo valores null
.The average of the sequence of values, or null
if the source
sequence is empty or contains only null
values.
Excepciones
source
o selector
es null
.source
or selector
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) para calcular la String longitud media en una secuencia de valores de tipo String .The following code example demonstrates how to use Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) to calculate the average String length in a sequence of values of type String.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, cambie el cuerpo de la función selector
.To extend the example to this topic, change the body of the selector
function.
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.
Comentarios
Este método tiene al menos un parámetro de tipo Expression<TDelegate> cuyo argumento de tipo es uno de los Func<T,TResult> tipos.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Para estos parámetros, puede pasar una expresión lambda y se compilará en un Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.
El Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>) método genera un MethodCallExpression que representa la llamada a Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>) sí mismo como un método genérico construido.The Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>) method generates a MethodCallExpression that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de después de source
invocar selector
en cada valor.The expected behavior is that it calculates the average of the values in source
after invoking selector
on each value.
Se aplica a
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>)
Calcula el promedio de una secuencia de valores Int32 que aceptan valores NULL que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of nullable Int32 values that is obtained by invoking a projection function on each element of the input sequence.
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,Nullable<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)
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
Parámetros
- source
- IQueryable<TSource>
Una secuencia de valores de la que se calculará el promedio.A sequence of values to calculate the average of.
- selector
- Expression<Func<TSource,Nullable<Int32>>>
Función de proyección que se va a aplicar a cada elemento.A projection function to apply to each element.
Devoluciones
Promedio de la secuencia de valores o null
si la secuencia source
está vacía o contiene solo valores null
.The average of the sequence of values, or null
if the source
sequence is empty or contains only null
values.
Excepciones
source
o selector
es null
.source
or selector
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) para calcular la String longitud media en una secuencia de valores de tipo String .The following code example demonstrates how to use Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) to calculate the average String length in a sequence of values of type String.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, cambie el cuerpo de la función selector
.To extend the example to this topic, change the body of the selector
function.
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.
Comentarios
Este método tiene al menos un parámetro de tipo Expression<TDelegate> cuyo argumento de tipo es uno de los Func<T,TResult> tipos.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Para estos parámetros, puede pasar una expresión lambda y se compilará en un Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.
El Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>) método genera un MethodCallExpression que representa la llamada a Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>) sí mismo como un método genérico construido.The Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>) method generates a MethodCallExpression that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de la IQueryProvider propiedad representada por Provider del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de después de source
invocar selector
en cada valor.The expected behavior is that it calculates the average of the values in source
after invoking selector
on each value.
Se aplica a
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>)
Calcula el promedio de una secuencia de valores Double que aceptan valores NULL que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of nullable Double values that is obtained by invoking a projection function on each element of the input sequence.
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,Nullable<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)
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
Parámetros
- source
- IQueryable<TSource>
Una secuencia de valores de la que se calculará el promedio.A sequence of values to calculate the average of.
- selector
- Expression<Func<TSource,Nullable<Double>>>
Función de proyección que se va a aplicar a cada elemento.A projection function to apply to each element.
Devoluciones
Promedio de la secuencia de valores o null
si la secuencia source
está vacía o contiene solo valores null
.The average of the sequence of values, or null
if the source
sequence is empty or contains only null
values.
Excepciones
source
o selector
es null
.source
or selector
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) para calcular la String longitud media en una secuencia de valores de tipo String .The following code example demonstrates how to use Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) to calculate the average String length in a sequence of values of type String.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, cambie el cuerpo de la función selector
.To extend the example to this topic, change the body of the selector
function.
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.
Comentarios
Este método tiene al menos un parámetro de tipo Expression<TDelegate> cuyo argumento de tipo es uno de los Func<T,TResult> tipos.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Para estos parámetros, puede pasar una expresión lambda y se compilará en un Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.
El Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>) método genera un MethodCallExpression que representa la llamada a Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>) sí mismo como un método genérico construido.The Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>) method generates a MethodCallExpression that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de después de source
invocar selector
en cada valor.The expected behavior is that it calculates the average of the values in source
after invoking selector
on each value.
Se aplica a
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,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
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
Parámetros
- source
- IQueryable<TSource>
Una secuencia de valores de la que se calculará el promedio.A sequence of values to calculate the average of.
- selector
- Expression<Func<TSource,Int64>>
Función de proyección que se va a aplicar a cada elemento.A projection function to apply to each element.
Devoluciones
El promedio de la secuencia de valores.The average of the sequence of values.
Excepciones
source
o selector
es null
.source
or selector
is null
.
source
no contiene ningún elemento.source
contains no elements.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) para calcular la String longitud media en una secuencia de valores de tipo String .The following code example demonstrates how to use Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) to calculate the average String length in a sequence of values of type String.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, cambie el cuerpo de la función selector
.To extend the example to this topic, change the body of the selector
function.
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.
Comentarios
Este método tiene al menos un parámetro de tipo Expression<TDelegate> cuyo argumento de tipo es uno de los Func<T,TResult> tipos.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Para estos parámetros, puede pasar una expresión lambda y se compilará en un Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.
El Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>) método genera un MethodCallExpression que representa la llamada a Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>) sí mismo como un método genérico construido.The Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>) method generates a MethodCallExpression that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de después de source
invocar selector
en cada valor.The expected behavior is that it calculates the average of the values in source
after invoking selector
on each value.
Se aplica a
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,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
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
Parámetros
- source
- IQueryable<TSource>
Una secuencia de valores de la que se calculará el promedio.A sequence of values to calculate the average of.
- selector
- Expression<Func<TSource,Int32>>
Función de proyección que se va a aplicar a cada elemento.A projection function to apply to each element.
Devoluciones
El promedio de la secuencia de valores.The average of the sequence of values.
Excepciones
source
o selector
es null
.source
or selector
is null
.
source
no contiene ningún elemento.source
contains no elements.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) para calcular la String longitud media en una secuencia de valores de tipo String .The following code example demonstrates how to use Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) to calculate the average String length in a sequence of values of type 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.
Comentarios
Este método tiene al menos un parámetro de tipo Expression<TDelegate> cuyo argumento de tipo es uno de los Func<T,TResult> tipos.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Para estos parámetros, puede pasar una expresión lambda y se compilará en un Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.
El Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) método genera un MethodCallExpression que representa la llamada a Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) sí mismo como un método genérico construido.The Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) method generates a MethodCallExpression that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de después de source
invocar selector
en cada valor.The expected behavior is that it calculates the average of the values in source
after invoking selector
on each value.
Se aplica a
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,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
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
Parámetros
- source
- IQueryable<TSource>
Una secuencia de valores de la que se calculará el promedio.A sequence of values to calculate the average of.
- selector
- Expression<Func<TSource,Double>>
Función de proyección que se va a aplicar a cada elemento.A projection function to apply to each element.
Devoluciones
El promedio de la secuencia de valores.The average of the sequence of values.
Excepciones
source
o selector
es null
.source
or selector
is null
.
source
no contiene ningún elemento.source
contains no elements.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) para calcular la String longitud media en una secuencia de valores de tipo String .The following code example demonstrates how to use Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) to calculate the average String length in a sequence of values of type String.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, cambie el cuerpo de la función selector
.To extend the example to this topic, change the body of the selector
function.
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.
Comentarios
Este método tiene al menos un parámetro de tipo Expression<TDelegate> cuyo argumento de tipo es uno de los Func<T,TResult> tipos.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Para estos parámetros, puede pasar una expresión lambda y se compilará en un Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.
El Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>) método genera un MethodCallExpression que representa la llamada a Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>) sí mismo como un método genérico construido.The Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>) method generates a MethodCallExpression that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de después de source
invocar selector
en cada valor.The expected behavior is that it calculates the average of the values in source
after invoking selector
on each value.
Se aplica a
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,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
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
Parámetros
- source
- IQueryable<TSource>
Secuencia de valores que se utilizan para calcular un promedio.A sequence of values that are used to calculate an average.
- selector
- Expression<Func<TSource,Decimal>>
Función de proyección que se va a aplicar a cada elemento.A projection function to apply to each element.
Devoluciones
El promedio de la secuencia de valores.The average of the sequence of values.
Excepciones
source
o selector
es null
.source
or selector
is null
.
source
no contiene ningún elemento.source
contains no elements.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) para calcular la String longitud media en una secuencia de valores de tipo String .The following code example demonstrates how to use Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) to calculate the average String length in a sequence of values of type String.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, cambie el cuerpo de la función selector
.To extend the example to this topic, change the body of the selector
function.
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.
Comentarios
Este método tiene al menos un parámetro de tipo Expression<TDelegate> cuyo argumento de tipo es uno de los Func<T,TResult> tipos.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Para estos parámetros, puede pasar una expresión lambda y se compilará en un Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.
El Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>) método genera un MethodCallExpression que representa la llamada a Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>) sí mismo como un método genérico construido.The Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>) method generates a MethodCallExpression that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de después de source
invocar selector
en cada valor.The expected behavior is that it calculates the average of the values in source
after invoking selector
on each value.
Se aplica a
Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>)
Calcula el promedio de una secuencia de valores Decimal que aceptan valores NULL que se obtiene al invocar una función de proyección en cada elemento de la secuencia de entrada.Computes the average of a sequence of nullable Decimal values that is obtained by invoking a projection function on each element of the input sequence.
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,Nullable<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)
Parámetros de tipo
- TSource
Tipo de los elementos de source
.The type of the elements of source
.
Parámetros
- source
- IQueryable<TSource>
Una secuencia de valores de la que se calculará el promedio.A sequence of values to calculate the average of.
- selector
- Expression<Func<TSource,Nullable<Decimal>>>
Función de proyección que se va a aplicar a cada elemento.A projection function to apply to each element.
Devoluciones
Promedio de la secuencia de valores o null
si la secuencia source
está vacía o contiene solo valores null
.The average of the sequence of values, or null
if the source
sequence is empty or contains only null
values.
Excepciones
source
o selector
es null
.source
or selector
is null
.
Ejemplos
En el ejemplo de código siguiente se muestra cómo utilizar Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) para calcular la String longitud media en una secuencia de valores de tipo String .The following code example demonstrates how to use Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>) to calculate the average String length in a sequence of values of type String.
Nota
En este ejemplo de código se usa una sobrecarga de este método sobrecargado diferente de la carga específica que se describe en este tema.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. Para ampliar el ejemplo a este tema, cambie el cuerpo de la función selector
.To extend the example to this topic, change the body of the selector
function.
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.
Comentarios
Este método tiene al menos un parámetro de tipo Expression<TDelegate> cuyo argumento de tipo es uno de los Func<T,TResult> tipos.This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. Para estos parámetros, puede pasar una expresión lambda y se compilará en un Expression<TDelegate> .For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.
El Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>) método genera un MethodCallExpression que representa la llamada a Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>) sí mismo como un método genérico construido.The Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>) method generates a MethodCallExpression that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>) itself as a constructed generic method. A continuación, pasa el MethodCallExpression al Execute<TResult>(Expression) método de IQueryProvider representado por la Provider propiedad del source
parámetro.It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source
parameter.
El comportamiento de la consulta que se produce como resultado de ejecutar un árbol de expresión que representa Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>) la llamada depende de la implementación del tipo del source
parámetro.The query behavior that occurs as a result of executing an expression tree that represents calling Average<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>) depends on the implementation of the type of the source
parameter. El comportamiento esperado es que calcule el promedio de los valores de después de source
invocar selector
en cada valor.The expected behavior is that it calculates the average of the values in source
after invoking selector
on each value.