Queryable.Max 메서드

정의

오버로드

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

제네릭 IQueryable<T>의 각 요소에 대해 프로젝션 함수를 호출하고 최대 결과 값을 반환합니다.

Max<TSource>(IQueryable<TSource>)

제네릭 IQueryable<T>의 최대값을 반환합니다.

Max<TSource>(IQueryable<TSource>, IComparer<TSource>)

제네릭 IQueryable<T>의 최대값을 반환합니다.

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

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

제네릭 IQueryable<T>의 각 요소에 대해 프로젝션 함수를 호출하고 최대 결과 값을 반환합니다.

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);
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 요소의 형식입니다.

TResult

selector에 지정된 함수가 반환하는 값의 형식입니다.

매개 변수

source
IQueryable<TSource>

최대값을 확인할 값의 시퀀스입니다.

selector
Expression<Func<TSource,TResult>>

각 요소에 적용할 프로젝션 함수입니다.

반환

TResult

시퀀스의 최대값입니다.

예외

source 또는 selectornull인 경우

source에 요소가 없는 경우

예제

다음 코드 예제에서는 를 사용하여 Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) 예상 값 시퀀스에서 최대값을 결정하는 방법을 보여 줍니다.

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> 의 매개 변수가 Func<T,TResult> 하나 이상 있습니다. 이러한 매개 변수의 경우 람다 식을 전달할 수 있으며 에 컴파일됩니다 Expression<TDelegate>.

메서드는 Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)MethodCallExpression 생성된 제네릭 메서드로 자신을 호출 Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) 하는 를 나타내는 을 생성합니다. 그런 다음 을 MethodCallExpression 매개 변수의 Execute<TResult>(Expression) 속성으로 나타내는 의 IQueryProvider 메서드에 Providersource 전달합니다.

호출 Max<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>) 을 나타내는 식 트리를 실행한 결과로 발생하는 쿼리 동작은 매개 변수 형식의 source 구현에 따라 달라집니다. 예상 동작은 의 각 요소 source 에서 를 호출 selector 하고 최대값을 반환하는 것입니다.

적용 대상

Max<TSource>(IQueryable<TSource>)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

제네릭 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);
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 요소의 형식입니다.

매개 변수

source
IQueryable<TSource>

최대값을 확인할 값의 시퀀스입니다.

반환

TSource

시퀀스의 최대값입니다.

예외

source이(가) null인 경우

source에 요소가 없는 경우

예제

다음 코드 예제에서는 를 사용하여 Max<TSource>(IQueryable<TSource>) 시퀀스의 최대값을 결정하는 방법을 보여 줍니다.

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>) 하는 를 나타내는 을 생성합니다. 그런 다음 을 MethodCallExpression 매개 변수의 Execute<TResult>(Expression) 속성으로 나타내는 의 IQueryProvider 메서드에 Providersource 전달합니다.

호출 Max<TSource>(IQueryable<TSource>) 을 나타내는 식 트리를 실행한 결과로 발생하는 쿼리 동작은 매개 변수 형식의 source 구현에 따라 달라집니다. 예상 동작은 의 최대값을 반환하는 것입니다 source.

적용 대상

Max<TSource>(IQueryable<TSource>, IComparer<TSource>)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

제네릭 IQueryable<T>의 최대값을 반환합니다.

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

형식 매개 변수

TSource

source 요소의 형식입니다.

매개 변수

source
IQueryable<TSource>

최대값을 확인할 값의 시퀀스입니다.

comparer
IComparer<TSource>

값을 비교할 IComparer<T>입니다.

반환

TSource

시퀀스의 최대값입니다.

예외

sourcenull입니다.

적용 대상