Method MinItems
| Edit this page View SourceMinItems<T>(IEnumerable<T>)
Returns all of the items that share the minimum value of a sequence.
Declaration
public static IEnumerable<T> MinItems<T>(this IEnumerable<T> source)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | source | The source sequence. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An IEnumerable<T> containing all of the items that share the minimum value. |
Type Parameters
Name | Description |
---|---|
T | Type of elements in the sequence. |
Remarks
This operator is a shortcut for DensePartialSort<T>(IEnumerable<T>, int, OrderByDirection)
with a direction
of Ascending and a count
of 1
.
This method is implemented by using deferred execution. However, source
will be consumed
in it's entirety immediately when first element of the returned sequence is consumed.
Examples
The following code example demonstrates how to get the minimum items from a sequence using MinItems
.
var sequence = new[]
{
"A", "B", "C", "D", "F",
"a", "b", "c", "d", "f",
}.AsEnumerable();
// Find the maximum items of the sequence
var result = sequence
.MinItems();
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [a]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
MinItems<T>(IEnumerable<T>, IComparer<T>?)
Returns all of the items that share the minimum value of a sequence.
Declaration
public static IEnumerable<T> MinItems<T>(this IEnumerable<T> source, IComparer<T>? comparer)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | source | The source sequence. |
IComparer<T> | comparer | A IComparer<T> to compare elements. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An IEnumerable<T> containing all of the items that share the minimum value. |
Type Parameters
Name | Description |
---|---|
T | Type of elements in the sequence. |
Remarks
This operator is a shortcut for DensePartialSort<T>(IEnumerable<T>, int, IComparer<T>?, OrderByDirection) with a count
of 1
.
This method is implemented by using deferred execution. However, source
will be consumed
in it's entirety immediately when first element of the returned sequence is consumed.
Examples
The following code example demonstrates how to get the minimum items from a sequence using MinItems
.
var sequence = new[]
{
"A", "B", "C", "D", "F",
"a", "b", "c", "d", "f",
}.AsEnumerable();
// Find the maximum items of the sequence
var result = sequence
.MinItems(StringComparer.OrdinalIgnoreCase);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [A, a]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|