Exactly - Kalkwst/Risotto GitHub Wiki

Definition

Determines whether or not the number of elements in the sequence is equal to the given limit.

In this page

Overloads

Overload Description
Exactly(int limit) Determines whether or not the number of elements in the sequence is equal to the given limit.

Exactly(int limit)

Determines whether or not the number of elements in the sequence is equal to the given limit.

public static bool Exactly<T>(this IEnumerable<T> source, int limit);

Type Parameters

T
The type of elements in source

Parameters

source IEnumerable<T>
The sequence to count the elements of.

limitInt32
The number of elements that should exist in source.

Returns

Boolean
true if the number of elements is equal to limit, false otherwise.

Exceptions

ArgumentNullException
source is null

ArgumentOutOfRangeException
limit is less than zero

Example

The following code example demonstrates how to use Exactly(int limit) to validate the number of elements in a sequence.

Array.Empty<int>().Exactly(0);
//=> true

Array.Empty<int>().Exactly(1);
//=> false

new int[] { 1 }.Exactly(0);
//=> false

new int[] { 1 }.Exactly(1);
//=> true
⚠️ **GitHub.com Fallback** ⚠️