SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method AtMost

    | Edit this page

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

    Determines whether or not the number of elements in the sequence is lesser than or equal to the given integer.

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

    The source sequence

    int count

    The maximum 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 lesser than or equal 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 a maximum size using AtMost.

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

    source is null.

    ArgumentOutOfRangeException

    count is negative.

    © SuperLinq Authors. All rights reserved.