by
84k 18
0
4
1,355
1
Top 1% !
Famous
Tagged
Specified
Popularity: 22465th place

Published on:

Architecturex86_64
LanguageC#
Windows VersionWindows7

MaxBy: Returns the maximal element of the given sequence, based on          the given projection.

// https://code.google.com/p/morelinq/source/browse/MoreLinq/        Returns the maximal element of the given sequence, based on
         the given projection.
       
         <remarks>
         If more than one element has the maximal projected value, the first
         one encountered will be returned. This overload uses the default comparer
         for the projected type. This operator uses immediate execution, but
         only buffers a single result (the current maximal element).
         </remarks>
         <typeparam name="TSource">Type of the source sequence</typeparam>
         <typeparam name="TKey">Type of the projected element</typeparam>
         <param name="source">Source sequence</param>
         <param name="selector">Selector to use to pick the results to compare</param>
         <returns>The maximal element, according to the projection.</returns>
         <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null</exception>
         <exception cref="InvalidOperationException"><paramref name="source"/> is empty</exception>
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1373953/MaxBy--Returns-the-maximal-element-of-th?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
using System; using System.Collections.Generic; // https://code.google.com/p/morelinq/source/browse/MoreLinq/MaxBy.cs /// <summary> /// Returns the maximal element of the given sequence, based on /// the given projection. /// </summary> /// <remarks> /// If more than one element has the maximal projected value, the first /// one encountered will be returned. This overload uses the default comparer /// for the projected type. This operator uses immediate execution, but /// only buffers a single result (the current maximal element). /// </remarks> /// <typeparam name="TSource">Type of the source sequence</typeparam> /// <typeparam name="TKey">Type of the projected element</typeparam> /// <param name="source">Source sequence</param> /// <param name="selector">Selector to use to pick the results to compare</param> /// <returns>The maximal element, according to the projection.</returns> /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null</exception> /// <exception cref="InvalidOperationException"><paramref name="source"/> is empty</exception> public static TSource MaxBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> selector) { return source.MaxBy(selector, Comparer<TKey>.Default); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus