최대 키 값을 사용하여 관찰 가능한 시퀀스의 요소를 반환합니다.
네임스페이스:System.Reactive.Linq
어셈블리: System.Reactive(System.Reactive.dll)
Syntax
'Declaration
<ExtensionAttribute> _
Public Shared Function MaxBy(Of TSource, TKey) ( _
source As IObservable(Of TSource), _
keySelector As Func(Of TSource, TKey) _
) As IObservable(Of IList(Of TSource))
'Usage
Dim source As IObservable(Of TSource)
Dim keySelector As Func(Of TSource, TKey)
Dim returnValue As IObservable(Of IList(Of TSource))
returnValue = source.MaxBy(keySelector)
public static IObservable<IList<TSource>> MaxBy<TSource, TKey>(
this IObservable<TSource> source,
Func<TSource, TKey> keySelector
)
[ExtensionAttribute]
public:
generic<typename TSource, typename TKey>
static IObservable<IList<TSource>^>^ MaxBy(
IObservable<TSource>^ source,
Func<TSource, TKey>^ keySelector
)
static member MaxBy :
source:IObservable<'TSource> *
keySelector:Func<'TSource, 'TKey> -> IObservable<IList<'TSource>>
JScript does not support generic types and methods.
형식 매개 변수
- TSource
원본의 형식입니다.
- TKey
키 형식입니다.
매개 변수
- source
형식: System.IObservable<TSource>
최대 요소를 가져오는 관찰 가능한 시퀀스입니다.
- keySelector
형식: System.Func<TSource, TKey>
키 선택기 함수입니다.
반환 값
형식: System.IObservable<IList<TSource>>
최대 키 값이 있는 관찰 가능한 시퀀스의 요소입니다.
사용 정보
Visual Basic 및 C#에서는 IObservable TSource> 형식의 모든 개체에서 이 메서드를 instance 메서드로 호출할 수 있습니다<. 인스턴스 메서드 구문을 사용하여 이 메서드를 호출할 경우에는 첫 번째 매개 변수를 생략합니다. 자세한 내용은 또는 를 참조하세요.
설명
MaxBy 연산자는 최대 키 값을 생성하는 시퀀스의 항목을 가져오는 데 사용됩니다. 예를 들어 시퀀스가 컴퓨터에서 실행되는 모든 프로세스의 시퀀스인 경우 MaxBy 연산자를 사용하여 가장 실제 메모리를 할당한 프로세스를 반환할 수 있습니다. 이 항목의 예제 코드는 이를 보여 줍니다.
예제
다음 예제 코드는 로컬 컴퓨터에서 실행 중인 모든 프로세스의 관찰 가능한 시퀀스를 만듭니다. 그런 다음 MaxBy 연산자는 가장 실제 메모리를 할당한 프로세스 목록을 포함하는 관찰 가능한 시퀀스를 반환하는 데 사용됩니다. 목록의 프로세스에 대한 프로세스 정보는 콘솔 창에 기록됩니다.
using System;
using System.Reactive.Linq;
using System.Diagnostics;
namespace Example
{
class Program
{
static void Main()
{
//*********************************************************************************************//
//*** Generate a sequence of processes running on the local machine. ***//
//*********************************************************************************************//
var seqProcesses = System.Diagnostics.Process.GetProcesses().ToObservable();
//*********************************************************************************************//
//*** Use the MaxBy operator to get a list of the processes that have the highest amount ***//
//*** of physical memory allocated. ***//
//*********************************************************************************************//
var maxWorkingSet = seqProcesses.MaxBy(p => p.WorkingSet64);
//*********************************************************************************************//
//*** Write the process information to the console window for the processes which have ***//
//*** allocated the most physical memory ***//
//*********************************************************************************************//
maxWorkingSet.Subscribe(maxList =>
{
foreach (Process process in maxList)
{
Console.WriteLine("\nDescription : {0}\n" +
"Filename : {1}\n" +
"Working Set : {2}",
process.MainModule.FileVersionInfo.FileDescription,
process.MainModule.FileName,
process.WorkingSet64);
}
});
Console.WriteLine("\nPress ENTER to exit...\n");
Console.ReadLine();
}
}
}
다음 출력은 예제 코드에 의해 생성되었습니다.
Description : Desktop Window Manager
Filename : C:\Windows\system32\Dwm.exe
Working Set : 363646976
Press ENTER to exit...