Queryable.Max Queryable.Max Queryable.Max Queryable.Max Method

定義

オーバーロード

Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)

ジェネリックの IQueryable<T> の各要素に対して射影関数を呼び出し、結果の最大値を返します。Invokes a projection function on each element of a generic IQueryable<T> and returns the maximum resulting value.

Max<TSource>(IQueryable<TSource>) Max<TSource>(IQueryable<TSource>) Max<TSource>(IQueryable<TSource>) Max<TSource>(IQueryable<TSource>)

ジェネリックの IQueryable<T> にある最大値を返します。Returns the maximum value in a generic IQueryable<T>.

Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)

ジェネリックの IQueryable<T> の各要素に対して射影関数を呼び出し、結果の最大値を返します。Invokes a projection function on each element of a generic IQueryable<T> and returns the maximum resulting value.

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

型パラメーター

TSource

source の要素の型。The type of the elements of source.

TResult

selector で表された関数によって返される値の型。The type of the value returned by the function represented by selector.

パラメーター

source
IQueryable<TSource>

最大値を確認する対象となる値のシーケンス。A sequence of values to determine the maximum of.

selector
Expression<Func<TSource,TResult>>

各要素に適用する射影関数。A projection function to apply to each element.

戻り値

TResult TResult TResult TResult

シーケンスの最大値。The maximum value in the sequence.

例外

source または selectornull です。source or selector is null.

次のコード例は、を使用Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)して、射影された値のシーケンスの最大値を確認する方法を示しています。The following code example demonstrates how to use Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) to determine the maximum value in a sequence of projected values.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MaxEx2()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    // Add Pet.Age to the length of Pet.Name
    // to determine the "maximum" Pet object in the array.
    int max =
        pets.AsQueryable().Max(pet => pet.Age + pet.Name.Length);

    Console.WriteLine(
        "The maximum pet age plus name length is {0}.",
        max);
}

/*
    This code produces the following output:

    The maximum pet age plus name length is 14.
*/

Structure Pet
    Public Name As String
    Public Age As Integer
End Structure

Shared Sub MaxEx2()
    Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8}, _
                   New Pet With {.Name = "Boots", .Age = 4}, _
                   New Pet With {.Name = "Whiskers", .Age = 1}}

    ' Add Pet.Age to the length of Pet.Name
    ' to determine the "maximum" Pet object in the array.
    Dim max As Integer = _
        pets.AsQueryable().Max(Function(pet) pet.Age + pet.Name.Length)

    MsgBox(String.Format("The maximum pet age plus name length is {0}.", max))

    'This code produces the following output:

    'The maximum pet age plus name length is 14.

注釈

このメソッドには、型引数が型Expression<TDelegate>の1つ以上の型のFunc<T,TResult>パラメーターが少なくとも1つ含まれています。This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. これらのパラメーターの場合は、ラムダ式を渡すことができ、にExpression<TDelegate>コンパイルされます。For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.

メソッドMax<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)は、構築MethodCallExpressionされたMax<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)ジェネリックメソッドとして呼び出し元を表すを生成します。The Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) method generates a MethodCallExpression that represents calling Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) itself as a constructed generic method. MethodCallExpressionに、 IQueryProvider Execute<TResult>(Expression) パラメーターsourceProviderプロパティによって表されるのメソッドにを渡します。It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

呼び出しMax<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)を表す式ツリーを実行した結果として発生するクエリ動作は、 sourceパラメーターの型の実装によって異なります。The query behavior that occurs as a result of executing an expression tree that represents calling Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) depends on the implementation of the type of the source parameter. 期待される動作は、のselector source各要素に対してを呼び出し、最大値を返すことです。The expected behavior is that it invokes selector on each element in source and returns the maximum value.

Max<TSource>(IQueryable<TSource>) Max<TSource>(IQueryable<TSource>) Max<TSource>(IQueryable<TSource>) Max<TSource>(IQueryable<TSource>)

ジェネリックの IQueryable<T> にある最大値を返します。Returns the maximum value in a generic IQueryable<T>.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static TSource Max(System::Linq::IQueryable<TSource> ^ source);
public static TSource Max<TSource> (this System.Linq.IQueryable<TSource> source);
static member Max : System.Linq.IQueryable<'Source> -> 'Source
<Extension()>
Public Function Max(Of TSource) (source As IQueryable(Of TSource)) As TSource

型パラメーター

TSource

source の要素の型。The type of the elements of source.

パラメーター

source
IQueryable<TSource>

最大値を確認する対象となる値のシーケンス。A sequence of values to determine the maximum of.

戻り値

TSource TSource TSource TSource

シーケンスの最大値。The maximum value in the sequence.

例外

次のコード例では、をMax<TSource>(IQueryable<TSource>)使用して、シーケンス内の最大値を確認する方法を示します。The following code example demonstrates how to use Max<TSource>(IQueryable<TSource>) to determine the maximum value in a sequence.

List<long> longs = new List<long> { 4294967296L, 466855135L, 81125L };

long max = longs.AsQueryable().Max();

Console.WriteLine("The largest number is {0}.", max);

/*
    This code produces the following output:

    The largest number is 4294967296.
*/

Dim longs As New List(Of Long)(New Long() {4294967296L, 466855135L, 81125L})

Dim max As Long = longs.AsQueryable().Max()

MsgBox(String.Format("The largest number is {0}.", max))

'This code produces the following output:

'The largest number is 4294967296.

注釈

メソッドMax<TSource>(IQueryable<TSource>)は、構築MethodCallExpressionされたMax<TSource>(IQueryable<TSource>)ジェネリックメソッドとして呼び出し元を表すを生成します。The Max<TSource>(IQueryable<TSource>) method generates a MethodCallExpression that represents calling Max<TSource>(IQueryable<TSource>) itself as a constructed generic method. MethodCallExpressionに、 IQueryProvider Execute<TResult>(Expression) パラメーターsourceProviderプロパティによって表されるのメソッドにを渡します。It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter.

呼び出しMax<TSource>(IQueryable<TSource>)を表す式ツリーを実行した結果として発生するクエリ動作は、 sourceパラメーターの型の実装によって異なります。The query behavior that occurs as a result of executing an expression tree that represents calling Max<TSource>(IQueryable<TSource>) depends on the implementation of the type of the source parameter. 期待される動作は、のsource最大値が返されることです。The expected behavior is that it returns the maximum value in source.

適用対象