You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Returns the minimum value in a generic sequence according to a specified key selector function.
1928
+
/// </summary>
1929
+
/// <typeparam name="TSource">The type of elements in <paramref name="source"/>.</typeparam>
1930
+
/// <typeparam name="TKey">The type of key to compare elements by.</typeparam>
1931
+
/// <param name="source">A <see cref="ReadOnlySpan{TSource}"/> to determine the minimum value of.</param>
1932
+
/// <param name="keySelector">A function to extract the key for each element.</param>
1933
+
/// <returns>The value with the minimum key in <paramref name="source"/>.</returns>
1934
+
/// <exception cref="ArgumentNullException"><paramref name="keySelector"/> is null.</exception>
1935
+
/// <exception cref="InvalidOperationException"><typeparamref name="TSource"/> is a primitive type and <paramref name="source"/> is empty.</exception>
1936
+
/// <remarks>If <paramref name="source"/> is empty and <typeparamref name="TSource"/> is a non-nullable struct, such as a primitive type, an <see cref="InvalidOperationException"/> is thrown.</remarks>
thrownewInvalidOperationException($"{nameof(source)} is empty");
1946
+
}
1947
+
1948
+
TSourcemin=source[0];
1949
+
TKeyminKey=keySelector(min);
1950
+
for(inti=1;i<source.Length;i++)
1951
+
{
1952
+
TSourcevalue=source[i];
1953
+
TKeycurrent=keySelector(value);
1954
+
if(current.CompareTo(minKey)<0)
1955
+
{
1956
+
min=value;
1957
+
minKey=current;
1958
+
}
1959
+
}
1960
+
returnmin;
1961
+
}
1962
+
1963
+
/// <summary>
1964
+
/// Returns the minimum value in a generic sequence according to a specified key selector function.
1965
+
/// </summary>
1966
+
/// <typeparam name="TSource">The type of elements in <paramref name="source"/>.</typeparam>
1967
+
/// <typeparam name="TKey">The type of key to compare elements by.</typeparam>
1968
+
/// <param name="source">A <see cref="ReadOnlySpan{TSource}"/> to determine the minimum value of.</param>
1969
+
/// <param name="keySelector">A function to extract the key for each element.</param>
1970
+
/// <param name="comparer">The <see cref="IComparer{TSource}"/> to compare keys.</param>
1971
+
/// <returns>The value with the minimum key in <paramref name="source"/>.</returns>
1972
+
/// <exception cref="ArgumentNullException"><paramref name="keySelector"/> is null.</exception>
1973
+
/// <exception cref="InvalidOperationException"><typeparamref name="TSource"/> is a primitive type and <paramref name="source"/> is empty.</exception>
1974
+
/// <remarks>If <paramref name="source"/> is empty and <typeparamref name="TSource"/> is a non-nullable struct, such as a primitive type, an <see cref="InvalidOperationException"/> is thrown.</remarks>
thrownewInvalidOperationException($"{nameof(source)} is empty");
1988
+
}
1989
+
1990
+
TSourcemin=source[0];
1991
+
TKeyminKey=keySelector(min);
1992
+
for(inti=1;i<source.Length;i++)
1993
+
{
1994
+
TSourcevalue=source[i];
1995
+
TKeycurrent=keySelector(value);
1996
+
if(comparer.Compare(current,minKey)<0)
1997
+
{
1998
+
min=value;
1999
+
minKey=current;
2000
+
}
2001
+
}
2002
+
returnmin;
2003
+
}
2004
+
2005
+
/// <summary>
2006
+
/// Returns the maximum value in a generic sequence according to a specified key selector function.
2007
+
/// </summary>
2008
+
/// <typeparam name="TSource">The type of elements in <paramref name="source"/>.</typeparam>
2009
+
/// <typeparam name="TKey">The type of key to compare elements by.</typeparam>
2010
+
/// <param name="source">A <see cref="ReadOnlySpan{TSource}"/> to determine the maximum value of.</param>
2011
+
/// <param name="keySelector">A function to extract the key for each element.</param>
2012
+
/// <returns>The value with the maximum key in <paramref name="source"/>.</returns>
2013
+
/// <exception cref="ArgumentNullException"><paramref name="keySelector"/> is null.</exception>
2014
+
/// <exception cref="InvalidOperationException"><typeparamref name="TSource"/> is a primitive type and <paramref name="source"/> is empty.</exception>
2015
+
/// <remarks>If <paramref name="source"/> is empty and <typeparamref name="TSource"/> is a non-nullable struct, such as a primitive type, an <see cref="InvalidOperationException"/> is thrown.</remarks>
thrownewInvalidOperationException($"{nameof(source)} is empty");
2025
+
}
2026
+
TSourcemax=source[0];
2027
+
TKeymaxKey=keySelector(max);
2028
+
for(inti=1;i<source.Length;i++)
2029
+
{
2030
+
TSourcevalue=source[i];
2031
+
TKeycurrent=keySelector(value);
2032
+
if(current.CompareTo(maxKey)>0)
2033
+
{
2034
+
max=value;
2035
+
maxKey=current;
2036
+
}
2037
+
}
2038
+
returnmax;
2039
+
}
2040
+
2041
+
/// <summary>
2042
+
/// Returns the maximum value in a generic sequence according to a specified key selector function.
2043
+
/// </summary>
2044
+
/// <typeparam name="TSource">The type of elements in <paramref name="source"/>.</typeparam>
2045
+
/// <typeparam name="TKey">The type of key to compare elements by.</typeparam>
2046
+
/// <param name="source">A <see cref="ReadOnlySpan{TSource}"/> to determine the maximum value of.</param>
2047
+
/// <param name="keySelector">A function to extract the key for each element.</param>
2048
+
/// <param name="comparer">The <see cref="IComparer{TSource}"/> to compare keys.</param>
2049
+
/// <returns>The value with the maximum key in <paramref name="source"/>.</returns>
2050
+
/// <exception cref="ArgumentNullException"><paramref name="keySelector"/> is null.</exception>
2051
+
/// <exception cref="InvalidOperationException"><typeparamref name="TSource"/> is a primitive type and <paramref name="source"/> is empty.</exception>
2052
+
/// <remarks>If <paramref name="source"/> is empty and <typeparamref name="TSource"/> is a non-nullable struct, such as a primitive type, an <see cref="InvalidOperationException"/> is thrown.</remarks>
0 commit comments