SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method Exactly

    | Edit this page

    Exactly<T>(IEnumerable<T>, int)

    Determines whether or not the number of elements in the sequence is equals to the given integer.

    Declaration
    public static bool Exactly<T>(this IEnumerable<T> source, int count)
    Parameters
    Type Name Description
    IEnumerable<T> source

    The source sequence

    int count

    The exactly number of items a sequence must have for this function to return true.

    Returns
    Type Description
    bool

    true if the number of elements in the sequence is equals to the given integer, false otherwise.

    Type Parameters
    Name Description
    T

    Element type of sequence

    Remarks

    This method executes immediately.

    Examples

    The following code example demonstrates how to check that a sequence has as an exact length using Exactly.

    var sequence = Enumerable.Range(1, 5);
                
    foreach (var x in Enumerable.Range(3, 5))
    {
        // Check that a sequence has an exact size
        var result = sequence.Exactly(x);
    
        Console.WriteLine($"Exactly {x}: {result}");
    }
    
    // This code produces the following output:
    // Exactly 3: False
    // Exactly 4: False
    // Exactly 5: True
    // Exactly 6: False
    // Exactly 7: False
    
    Exceptions
    Type Condition
    ArgumentNullException

    source is null.

    ArgumentOutOfRangeException

    count is negative.

    © SuperLinq Authors. All rights reserved.