Method CompareCount
| Edit this page View SourceCompareCount<TFirst, TSecond>(IEnumerable<TFirst>, IEnumerable<TSecond>)
Compares two sequences and returns an integer that indicates whether the first sequence has fewer, the same or more elements than the second sequence.
Declaration
public static int CompareCount<TFirst, TSecond>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TFirst> | first | The first sequence. |
IEnumerable<TSecond> | second | The second sequence. |
Returns
Type | Description |
---|---|
int |
|
Type Parameters
Name | Description |
---|---|
TFirst | Element type of the first sequence. |
TSecond | Element type of the second sequence. |
Remarks
This method executes immediately.
Examples
The following code example demonstrates to compare the length of two sequences using CompareCount
.
var sequence = Enumerable.Range(1, 5);
foreach (var x in Enumerable.Range(3, 5))
{
// Compare the length of two sequences
var result = sequence.CompareCount(Enumerable.Range(1, x));
Console.WriteLine($"CompareCount {x}: {result}");
}
// This code produces the following output:
// CompareCount 3: 1
// CompareCount 4: 1
// CompareCount 5: 0
// CompareCount 6: -1
// CompareCount 7: -1
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|