SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method Split

    | Edit this page

    Split<TSource>(IEnumerable<TSource>, TSource)

    Splits the source sequence by a separator.

    Declaration
    public static IEnumerable<IReadOnlyList<TSource>> Split<TSource>(this IEnumerable<TSource> source, TSource separator)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    TSource separator

    Separator element.

    Returns
    Type Description
    IEnumerable<IReadOnlyList<TSource>>

    A sequence of splits of elements.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Examples

    The following code example demonstrates how to split a sequence based on a value using Split.

    var sequence = Enumerable.Range(0, 11);
    
    // split a sequence using a key value
    var result = sequence
        .Split(5);
    
    Console.WriteLine(
        "[" + Environment.NewLine + 
        string.Join(
            ", " + Environment.NewLine,
            result.Select(c => "   [" + string.Join(", ", c) + "]")) +
        Environment.NewLine + "]");
    
    // This code produces the following output:
    // [
    //    [0, 1, 2, 3, 4],
    //    [6, 7, 8, 9, 10]
    // ]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source is null.

    | Edit this page

    Split<TSource>(IEnumerable<TSource>, TSource, int)

    Splits the source sequence by a separator given a maximum count of splits.

    Declaration
    public static IEnumerable<IReadOnlyList<TSource>> Split<TSource>(this IEnumerable<TSource> source, TSource separator, int count)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    TSource separator

    Separator element.

    int count

    Maximum number of splits.

    Returns
    Type Description
    IEnumerable<IReadOnlyList<TSource>>

    A sequence of splits of elements.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Examples

    The following code example demonstrates how to split a sequence based on a value using Split.

    var sequence = Enumerable.Range(0, 3).Repeat(10);
    
    // split a sequence using a key value
    var result = sequence
        .Split(2, 4);
    
    Console.WriteLine(
        "[" + Environment.NewLine + 
        string.Join(
            ", " + Environment.NewLine,
            result.Select(c => "   [" + string.Join(", ", c) + "]")) +
        Environment.NewLine + "]");
    
    // This code produces the following output:
    // [
    //    [0, 1],
    //    [0, 1],
    //    [0, 1],
    //    [0, 1],
    //    [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]
    // ]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source is null.

    ArgumentOutOfRangeException

    count is less than 1.

    Split<TSource, TResult>(IEnumerable<TSource>, TSource, Func<IReadOnlyList<TSource>, TResult>)

    Splits the source sequence by a separator and then transforms the splits into results.

    Declaration
    public static IEnumerable<TResult> Split<TSource, TResult>(this IEnumerable<TSource> source, TSource separator, Func<IReadOnlyList<TSource>, TResult> resultSelector)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    TSource separator

    Separator element.

    Func<IReadOnlyList<TSource>, TResult> resultSelector

    Function used to project splits of source elements into elements of the resulting sequence.

    Returns
    Type Description
    IEnumerable<TResult>

    A sequence of values typed as TResult.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    TResult

    Type of the result sequence elements.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Exceptions
    Type Condition
    ArgumentNullException

    source or resultSelector is null.

    Split<TSource, TResult>(IEnumerable<TSource>, TSource, int, Func<IReadOnlyList<TSource>, TResult>)

    Splits the source sequence by a separator, given a maximum count of splits, and then transforms the splits into results.

    Declaration
    public static IEnumerable<TResult> Split<TSource, TResult>(this IEnumerable<TSource> source, TSource separator, int count, Func<IReadOnlyList<TSource>, TResult> resultSelector)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    TSource separator

    Separator element.

    int count

    Maximum number of splits.

    Func<IReadOnlyList<TSource>, TResult> resultSelector

    Function used to project splits of source elements into elements of the resulting sequence.

    Returns
    Type Description
    IEnumerable<TResult>

    A sequence of values typed as TResult.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    TResult

    Type of the result sequence elements.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Exceptions
    Type Condition
    ArgumentNullException

    source or resultSelector is null.

    ArgumentOutOfRangeException

    count is less than 1.

    | Edit this page

    Split<TSource>(IEnumerable<TSource>, TSource, IEqualityComparer<TSource>?)

    Splits the source sequence by a separator and then transforms the splits into results.

    Declaration
    public static IEnumerable<IReadOnlyList<TSource>> Split<TSource>(this IEnumerable<TSource> source, TSource separator, IEqualityComparer<TSource>? comparer)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    TSource separator

    Separator element.

    IEqualityComparer<TSource> comparer

    Comparer used to determine separator element equality.

    Returns
    Type Description
    IEnumerable<IReadOnlyList<TSource>>

    A sequence of splits of elements.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Examples

    The following code example demonstrates how to split a sequence based on a value using Split.

    var sequence = Enumerable.Range(0, 11);
    
    // split a sequence using a key value
    var result = sequence
        .Split(5, EqualityComparer<int>.Default);
    
    Console.WriteLine(
        "[" + Environment.NewLine + 
        string.Join(
            ", " + Environment.NewLine,
            result.Select(c => "   [" + string.Join(", ", c) + "]")) +
        Environment.NewLine + "]");
    
    // This code produces the following output:
    // [
    //    [0, 1, 2, 3, 4],
    //    [6, 7, 8, 9, 10]
    // ]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source is null.

    | Edit this page

    Split<TSource>(IEnumerable<TSource>, TSource, IEqualityComparer<TSource>?, int)

    Splits the source sequence by a separator, given a maximum count of splits. A parameter specifies how the separator is compared for equality.

    Declaration
    public static IEnumerable<IReadOnlyList<TSource>> Split<TSource>(this IEnumerable<TSource> source, TSource separator, IEqualityComparer<TSource>? comparer, int count)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    TSource separator

    Separator element.

    IEqualityComparer<TSource> comparer

    Comparer used to determine separator element equality.

    int count

    Maximum number of splits.

    Returns
    Type Description
    IEnumerable<IReadOnlyList<TSource>>

    A sequence of splits of elements.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Examples

    The following code example demonstrates how to split a sequence based on a value using Split.

    var sequence = Enumerable.Range(0, 3).Repeat(10);
    
    // split a sequence using a key value
    var result = sequence
        .Split(2, EqualityComparer<int>.Default, 4);
    
    Console.WriteLine(
        "[" + Environment.NewLine + 
        string.Join(
            ", " + Environment.NewLine,
            result.Select(c => "   [" + string.Join(", ", c) + "]")) +
        Environment.NewLine + "]");
    
    // This code produces the following output:
    // [
    //    [0, 1],
    //    [0, 1],
    //    [0, 1],
    //    [0, 1],
    //    [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]
    // ]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source is null.

    ArgumentOutOfRangeException

    count is less than 1.

    Split<TSource, TResult>(IEnumerable<TSource>, TSource, IEqualityComparer<TSource>, Func<IReadOnlyList<TSource>, TResult>)

    Splits the source sequence by a separator and then transforms the splits into results. A parameter specifies how the separator is compared for equality.

    Declaration
    public static IEnumerable<TResult> Split<TSource, TResult>(this IEnumerable<TSource> source, TSource separator, IEqualityComparer<TSource> comparer, Func<IReadOnlyList<TSource>, TResult> resultSelector)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    TSource separator

    Separator element.

    IEqualityComparer<TSource> comparer

    Comparer used to determine separator element equality.

    Func<IReadOnlyList<TSource>, TResult> resultSelector

    Function used to project splits of source elements into elements of the resulting sequence.

    Returns
    Type Description
    IEnumerable<TResult>

    A sequence of values typed as TResult.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    TResult

    Type of the result sequence elements.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Exceptions
    Type Condition
    ArgumentNullException

    source or resultSelector is null.

    Split<TSource, TResult>(IEnumerable<TSource>, TSource, IEqualityComparer<TSource>?, int, Func<IReadOnlyList<TSource>, TResult>)

    Splits the source sequence by a separator, given a maximum count of splits, and then transforms the splits into results. A parameter specifies how the separator is compared for equality.

    Declaration
    public static IEnumerable<TResult> Split<TSource, TResult>(this IEnumerable<TSource> source, TSource separator, IEqualityComparer<TSource>? comparer, int count, Func<IReadOnlyList<TSource>, TResult> resultSelector)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    TSource separator

    Separator element.

    IEqualityComparer<TSource> comparer

    Comparer used to determine separator element equality.

    int count

    Maximum number of splits.

    Func<IReadOnlyList<TSource>, TResult> resultSelector

    Function used to project splits of source elements into elements of the resulting sequence.

    Returns
    Type Description
    IEnumerable<TResult>

    A sequence of values typed as TResult.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    TResult

    Type of the result sequence elements.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Exceptions
    Type Condition
    ArgumentNullException

    source or resultSelector is null.

    ArgumentOutOfRangeException

    count is less than 1.

    | Edit this page

    Split<TSource>(IEnumerable<TSource>, Func<TSource, bool>)

    Splits the source sequence by separator elements identified by a function.

    Declaration
    public static IEnumerable<IReadOnlyList<TSource>> Split<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> separatorFunc)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    Func<TSource, bool> separatorFunc

    Predicate function used to determine the splitter elements in the source sequence.

    Returns
    Type Description
    IEnumerable<IReadOnlyList<TSource>>

    A sequence of splits of elements.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Examples

    The following code example demonstrates how to split a sequence based on a condition using Split.

    var sequence = Enumerable.Range(0, 11);
    
    // split a sequence using a key value
    var result = sequence
        .Split(x => x % 3 == 2);
    
    Console.WriteLine(
        "[" + Environment.NewLine + 
        string.Join(
            ", " + Environment.NewLine,
            result.Select(c => "   [" + string.Join(", ", c) + "]")) +
        Environment.NewLine + "]");
    
    // This code produces the following output:
    // [
    //    [0, 1],
    //    [3, 4],
    //    [6, 7],
    //    [9, 10]
    // ]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source or separatorFunc is null.

    | Edit this page

    Split<TSource>(IEnumerable<TSource>, Func<TSource, bool>, int)

    Splits the source sequence by separator elements identified by a function, given a maximum count of splits.

    Declaration
    public static IEnumerable<IReadOnlyList<TSource>> Split<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> separatorFunc, int count)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    Func<TSource, bool> separatorFunc

    Predicate function used to determine the splitter elements in the source sequence.

    int count

    Maximum number of splits.

    Returns
    Type Description
    IEnumerable<IReadOnlyList<TSource>>

    A sequence of splits of elements.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Examples

    The following code example demonstrates how to split a sequence based on a condition using Split.

    var sequence = Enumerable.Range(0, 11);
    
    // split a sequence using a key value
    var result = sequence
        .Split(x => x % 3 == 2, 2);
    
    Console.WriteLine(
        "[" + Environment.NewLine + 
        string.Join(
            ", " + Environment.NewLine,
            result.Select(c => "   [" + string.Join(", ", c) + "]")) +
        Environment.NewLine + "]");
    
    // This code produces the following output:
    // [
    //    [0, 1],
    //    [3, 4],
    //    [6, 7, 8, 9, 10]
    // ]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source or separatorFunc is null.

    ArgumentOutOfRangeException

    count is less than 1.

    Split<TSource, TResult>(IEnumerable<TSource>, Func<TSource, bool>, Func<IReadOnlyList<TSource>, TResult>)

    Splits the source sequence by separator elements identified by a function and then transforms the splits into results.

    Declaration
    public static IEnumerable<TResult> Split<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, bool> separatorFunc, Func<IReadOnlyList<TSource>, TResult> resultSelector)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    Func<TSource, bool> separatorFunc

    Predicate function used to determine the splitter elements in the source sequence.

    Func<IReadOnlyList<TSource>, TResult> resultSelector

    Function used to project splits of source elements into elements of the resulting sequence.

    Returns
    Type Description
    IEnumerable<TResult>

    A sequence of values typed as TResult.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    TResult

    Type of the result sequence elements.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Exceptions
    Type Condition
    ArgumentNullException

    source, separatorFunc, or resultSelector is null.

    Split<TSource, TResult>(IEnumerable<TSource>, Func<TSource, bool>, int, Func<IReadOnlyList<TSource>, TResult>)

    Splits the source sequence by separator elements identified by a function, given a maximum count of splits, and then transforms the splits into results.

    Declaration
    public static IEnumerable<TResult> Split<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, bool> separatorFunc, int count, Func<IReadOnlyList<TSource>, TResult> resultSelector)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    The source sequence.

    Func<TSource, bool> separatorFunc

    Predicate function used to determine the splitter elements in the source sequence.

    int count

    Maximum number of splits.

    Func<IReadOnlyList<TSource>, TResult> resultSelector

    Function used to project a split group of source elements into an element of the resulting sequence.

    Returns
    Type Description
    IEnumerable<TResult>

    A sequence of values typed as TResult.

    Type Parameters
    Name Description
    TSource

    Type of element in the source sequence.

    TResult

    Type of the result sequence elements.

    Remarks

    This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.

    Exceptions
    Type Condition
    ArgumentNullException

    source, separatorFunc, or resultSelector is null.

    ArgumentOutOfRangeException

    count is less than 1.

    © SuperLinq Authors. All rights reserved.