Class EnumerableExtensions | Localization | 0.6.1-preview
docs.unity3d.com
    Show / Hide Table of Contents

    Class EnumerableExtensions

    Inheritance
    Object
    EnumerableExtensions
    Namespace: UnityEngine.Localization.SmartFormat.Tests.Common
    Syntax
    public static class EnumerableExtensions

    Methods

    Concat<T>(IEnumerable<T>, T[])

    Concatenates the first sequence with the specified items.

    This method is an overload for Concat that uses the params argument to provide a better syntax when used with a known set of items.

    Declaration
    public static IEnumerable<T> Concat<T>(this IEnumerable<T> first, params T[] secondItems)
    Parameters
    Type Name Description
    IEnumerable<T> first
    T[] secondItems
    Returns
    Type Description
    IEnumerable<T>
    Type Parameters
    Name Description
    T

    ForEach<TSource>(IEnumerable<TSource>, Action<TSource, Int32>)

    Performs an action for each item in the list. For simple actions, this provides an easier syntax than the normal foreach loop.

    Declaration
    public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource, int> action)
    Parameters
    Type Name Description
    IEnumerable<TSource> source
    Action<TSource, Int32> action

    This action method takes into account the index of the item.

    Type Parameters
    Name Description
    TSource

    ForEach<TSource>(IEnumerable<TSource>, Action<TSource>)

    Performs an action for each item in the list. For simple actions, this provides an easier syntax than the normal foreach loop.

    Declaration
    public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource> action)
    Parameters
    Type Name Description
    IEnumerable<TSource> source
    Action<TSource> action
    Type Parameters
    Name Description
    TSource

    FormatEach<T>(IEnumerable<T>, String)

    Uses String.Format to format each item in the collection using the specified format.

    Declaration
    public static IEnumerable<string> FormatEach<T>(this IEnumerable<T> source, string format)
    Parameters
    Type Name Description
    IEnumerable<T> source
    String format

    A composite format string; same as String.Format. {0} refers to the source object, {1} refers to the index.

    Returns
    Type Description
    IEnumerable<String>
    Type Parameters
    Name Description
    T

    JoinStrings(IEnumerable<String>, String)

    Joins all strings together into a single string, separating each item with the separator.

    For example:

    alphabet.JoinStrings(", ") == "a, b, ... y, z"

    Declaration
    public static string JoinStrings(this IEnumerable<string> source, string separator)
    Parameters
    Type Name Description
    IEnumerable<String> source

    The source of strings to join together

    String separator

    The text to insert between items

    Returns
    Type Description
    String

    JoinStrings(IEnumerable<String>, String, String)

    Joins all strings together into a single string, separating each item with the separator, and separating the last item with an alternate separator.

    For example:

    alphabet.JoinStrings(", ", " and ") == "a, b, ... x, y and z"

    Declaration
    public static string JoinStrings(this IEnumerable<string> source, string separator, string lastSeparator)
    Parameters
    Type Name Description
    IEnumerable<String> source
    String separator
    String lastSeparator
    Returns
    Type Description
    String

    JoinStrings(IEnumerable<String>, String, String, String, Int32)

    Joins all strings together into a single string, separating each item with the separator, and separating the last item with an alternate separator. Allows you to specify a cutoff, so that further items will not be displayed.

    For example:

    alphabet.JoinStrings(", ", " and ", 4, " and {0} others...") == "a, b, c, d and 22 others..."

    Declaration
    public static string JoinStrings(this IEnumerable<string> source, string separator, string lastSeparator, string cutoffText, int cutoff)
    Parameters
    Type Name Description
    IEnumerable<String> source
    String separator

    This string will be inserted between items.

    String lastSeparator

    This string will be inserted before the last item, instead of the separator.

    String cutoffText

    The text that will be used if the cutoff is reached. For example, " and {0} others..." Optional placeholders: {0} = cutoff count, {1} = source count

    Int32 cutoff

    Limits the number of items. If the limit is reached, then cutoffText is appended.

    Returns
    Type Description
    String

    Random<T>(IEnumerable<T>)

    Chooses one of the items at random.

    Throws an exception if there are no items.

    Declaration
    public static T Random<T>(this IEnumerable<T> source)
    Parameters
    Type Name Description
    IEnumerable<T> source
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    RandomOrDefault<T>(IEnumerable<T>)

    Chooses one of the items at random.

    Returns default if there are no items.

    Declaration
    public static T RandomOrDefault<T>(this IEnumerable<T> source)
    Parameters
    Type Name Description
    IEnumerable<T> source
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

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

    Splits the enumeration into segments, each segment containing the portion between predicate matches.

    Declaration
    public static IEnumerable<TSource[]> Split<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> splitPredicate)
    Parameters
    Type Name Description
    IEnumerable<TSource> source
    Func<TSource, Boolean> splitPredicate

    The condition that will create a new split. The matching item will be the first element in the new split.

    Returns
    Type Description
    IEnumerable<TSource[]>
    Type Parameters
    Name Description
    TSource

    Split<TSource>(IEnumerable<TSource>, Func<TSource, Int32, Boolean>)

    Splits the enumeration into segments, each segment containing the portion between predicate matches.

    Declaration
    public static IEnumerable<TSource[]> Split<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> splitPredicate)
    Parameters
    Type Name Description
    IEnumerable<TSource> source
    Func<TSource, Int32, Boolean> splitPredicate

    The condition that will create a new split. The matching item will be the first element in the new split. This predicate incorporates the element's index.

    Returns
    Type Description
    IEnumerable<TSource[]>
    Type Parameters
    Name Description
    TSource

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

    Splits the enumeration into segments, each segment containing [count] items, and the last segment containing the remainder.

    Declaration
    public static IEnumerable<TSource[]> Split<TSource>(this IEnumerable<TSource> source, int count)
    Parameters
    Type Name Description
    IEnumerable<TSource> source
    Int32 count

    The number of items to include in each segment. The last segment might contain fewer items.

    Returns
    Type Description
    IEnumerable<TSource[]>
    Type Parameters
    Name Description
    TSource

    SplitAfter<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>)

    Splits the enumeration into segments, each segment containing the portion between predicate matches.

    Declaration
    public static IEnumerable<TSource[]> SplitAfter<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> splitPredicate)
    Parameters
    Type Name Description
    IEnumerable<TSource> source
    Func<TSource, Boolean> splitPredicate

    The condition that will create a new split. The matching item will be the last element in the previous split.

    Returns
    Type Description
    IEnumerable<TSource[]>
    Type Parameters
    Name Description
    TSource

    SplitAfter<TSource>(IEnumerable<TSource>, Func<TSource, Int32, Boolean>)

    Splits the enumeration into segments, each segment containing the portion between predicate matches.

    Declaration
    public static IEnumerable<TSource[]> SplitAfter<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> splitPredicate)
    Parameters
    Type Name Description
    IEnumerable<TSource> source
    Func<TSource, Int32, Boolean> splitPredicate

    The condition that will create a new split. The matching item will be the last element in the previous split. This predicate incorporates the element's index.

    Returns
    Type Description
    IEnumerable<TSource[]>
    Type Parameters
    Name Description
    TSource

    Union<T>(IEnumerable<T>, T[])

    Produces the set union of the first sequence and the specified items by using the default equality comparer.

    This method is an overload for Union that uses the params argument to provide a better syntax when used with a known set of items.

    Declaration
    public static IEnumerable<T> Union<T>(this IEnumerable<T> first, params T[] secondItems)
    Parameters
    Type Name Description
    IEnumerable<T> first
    T[] secondItems
    Returns
    Type Description
    IEnumerable<T>
    Type Parameters
    Name Description
    T
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023