Class EnumerableExtensions
Extensions for all items of type IEnumerable<T>.
Inherited Members
Namespace: TheXDS.MCART.Types.Extensions
Assembly: MCART.dll
Syntax
public static class EnumerableExtensions
Methods
| Edit this page View SourceAreAllEqual<T>(IEnumerable<T>)
Checks whether all objects in the collection are equal.
Declaration
public static bool AreAllEqual<T>(this IEnumerable<T> c)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | c | Collection containing the objects to check. |
Returns
| Type | Description |
|---|---|
| bool | true if all objects in the collection are equal, false otherwise. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of objects in the collection. |
AreAllEqual<T, TProp>(IEnumerable<T>, Func<T, TProp>)
Checks whether the property or value within all objects in the collection are equal.
Declaration
public static bool AreAllEqual<T, TProp>(this IEnumerable<T> c, Func<T, TProp> selector)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | c | Collection containing the objects to check. |
| Func<T, TProp> | selector | Selector function for the value of each object. |
Returns
| Type | Description |
|---|---|
| bool | true if all selected values from the objects in the collection are equal, false otherwise. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of objects in the collection. |
| TProp | Type of value to compare. |
Contains(IEnumerable, object?)
Non-generic version of the function Contains<TSource>(IEnumerable<TSource>, TSource).
Declaration
public static bool Contains(this IEnumerable enumerable, object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | enumerable | Collection to check. |
| object | obj | Object to search within the collection. |
Returns
| Type | Description |
|---|---|
| bool | true if the collection contains the specified object, false otherwise. |
ContainsAll(IEnumerable, IEnumerable)
Checks if the collection contains all
the elements of the items collection.
Declaration
public static bool ContainsAll(this IEnumerable collection, IEnumerable items)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | collection | Enumeration to check. |
| IEnumerable | items | Elements that must exist in |
Returns
| Type | Description |
|---|---|
| bool | true if |
ContainsAll(IEnumerable, params object?[])
Checks if the collection contains all
the elements of the items collection.
Declaration
public static bool ContainsAll(this IEnumerable collection, params object?[] items)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | collection | Enumeration to check. |
| object[] | items | Elements that must exist in |
Returns
| Type | Description |
|---|---|
| bool | true if |
ContainsAny(IEnumerable, IEnumerable)
Checks if the collection contains any
of the elements of the items collection.
Declaration
public static bool ContainsAny(this IEnumerable collection, IEnumerable items)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | collection | Enumeration to check. |
| IEnumerable | items | Elements that must exist in |
Returns
| Type | Description |
|---|---|
| bool | true if |
ContainsAny(IEnumerable, params object?[])
Checks if the collection contains any
of the elements of the items collection.
Declaration
public static bool ContainsAny(this IEnumerable collection, params object?[] items)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | collection | Enumeration to check. |
| object[] | items | Elements that must exist in |
Returns
| Type | Description |
|---|---|
| bool | true if |
Copy<T>(IEnumerable<T>)
Returns a copy of the elements of this IEnumerable<T>
Declaration
public static IEnumerable<T> Copy<T>(this IEnumerable<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Collection to copy. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | Copy of this list. The elements of the copy represent the same instance of the original object. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the IEnumerable<T>. |
Count(IEnumerable)
Non-generic version of the function Count<TSource>(IEnumerable<TSource>). Gets the number of elements in a sequence.
Declaration
public static int Count(this IEnumerable e)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | e | Sequence to check. The same will be enumerated. |
Returns
| Type | Description |
|---|---|
| int | The number of elements within the sequence. |
ExceptFor<T>(IEnumerable<T>, params T[])
Enumerates all elements of the collection, omitting the specified ones.
Declaration
public static IEnumerable<T> ExceptFor<T>(this IEnumerable<T> collection, params T[] exclusions)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Collection to enumerate. |
| T[] | exclusions | Elements to exclude from the collection. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumeration with the elements of the collection, omitting the specified exclusions. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements in the collection. |
FindIndexOf<T>(IEnumerable<T>, T)
Finds the index of an object within a collection.
Declaration
public static int FindIndexOf<T>(this IEnumerable<T> e, T item)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | e | Collection containing the objects to check. |
| T | item | Item to get the index of. |
Returns
| Type | Description |
|---|---|
| int | The index of the specified object, or |
Type Parameters
| Name | Description |
|---|---|
| T | Type of objects in the collection. |
FirstOf<T>(IEnumerable<T>, Type)
Gets the first element of the requested type within a collection.
Declaration
[RequiresDynamicCode("The method dynamically creates new types, so it is not compatible with trimming.")]
public static T FirstOf<T>(this IEnumerable<T> collection, Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Collection over which to perform the search. |
| Type | type | Type of element to search for. |
Returns
| Type | Description |
|---|---|
| T | The first element of type |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the collection. |
FirstOf<T>(IEnumerable)
Gets the first element of the requested type within a collection.
Declaration
public static T FirstOf<T>(this IEnumerable collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | collection | Collection on which to perform the search. |
Returns
| Type | Description |
|---|---|
| T | The first element of type |
Type Parameters
| Name | Description |
|---|---|
| T | Type of element to search for. |
GroupByType(IEnumerable)
Groups a sequence of elements according to their types.
Declaration
public static IEnumerable<IGrouping<Type, object>> GroupByType(this IEnumerable c)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | c | Collection to group. |
Returns
| Type | Description |
|---|---|
| IEnumerable<IGrouping<Type, object>> | A sequence of elements grouped according to their type. |
Interleave<T>(IEnumerable<IEnumerable<T>>)
Interleaves a collection of sequences into a single sequence.
Declaration
public static IEnumerable<T> Interleave<T>(this IEnumerable<IEnumerable<T>> collections)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<IEnumerable<T>> | collections | Enumeration of sequences to interleave |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumeration where the elements of all sequences are interleaved. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements in the sequences. |
Interleave<T>(IEnumerable<T>, IEnumerable<T>)
Interleaves two sequences into a single sequence.
Declaration
public static IEnumerable<T> Interleave<T>(this IEnumerable<T> first, IEnumerable<T> second)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | first | First sequence. |
| IEnumerable<T> | second | Second sequence |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumeration where the elements of both sequences are interleaved. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements in the sequences. |
IsAnyOf(IEnumerable, Type)
Checks whether the collection contains at least one element of the specified type.
Declaration
public static bool IsAnyOf(this IEnumerable collection, Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | collection | Collection of elements to check. |
| Type | type | Type of object to search for. |
Returns
| Type | Description |
|---|---|
| bool | true if there is an element of the specified type in the collection, false otherwise. |
IsAnyOf<T>(IEnumerable)
Checks whether the collection contains at least one element of the specified type.
Declaration
public static bool IsAnyOf<T>(this IEnumerable collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | collection | Collection of elements to check. |
Returns
| Type | Description |
|---|---|
| bool | true if there is an element of the specified type in the collection, false otherwise. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of object to search for. |
IsPropertyEqual<T>(IEnumerable<T>, Func<T, object>)
Gets a value that indicates whether the value of the property of all objects in the collection is equal.
Declaration
public static bool IsPropertyEqual<T>(this IEnumerable<T> c, Func<T, object> selector)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | c | Collection containing the objects to check. |
| Func<T, object> | selector | Selector function. |
Returns
| Type | Description |
|---|---|
| bool | true if the value of the property of all objects in the collection is the same, false otherwise. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of objects in the collection. |
IsQuorum<T>(IEnumerable<T>, int, out T)
Determines whether a quorum is met for a specified value in a collection.
Declaration
public static bool IsQuorum<T>(this IEnumerable<T> values, int quorumCount, out T value) where T : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | values | The collection of values to evaluate. |
| int | quorumCount | The minimum number of occurrences required for a value to meet the quorum. Must be greater than or equal to 1. |
| T | value | When this method returns true, contains the value
that meets the quorum. When this method returns
false, contains the default value for the type
|
Returns
| Type | Description |
|---|---|
| bool | true if a value in the collection meets or exceeds the specified quorum count; otherwise, false. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of elements in the collection. Must be a non-nullable type. |
Remarks
This method evaluates the collection to determine if any value appears
at least quorumCount times. If multiple values meet
the quorum, the value with the highest occurrence is selected. If there
is a tie, the first value encountered in the collection is returned.
ItemsEqual(IEnumerable, IEnumerable)
Compares two collections and determines if their elements are equal.
Declaration
public static bool ItemsEqual(this IEnumerable collection, IEnumerable items)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | collection | Enumeration to check. |
| IEnumerable | items | Enumeration against which to check. |
Returns
| Type | Description |
|---|---|
| bool | true if the elements of both collections are equal, false otherwise. |
Joint<T>(IEnumerable<IEnumerable<T>>)
Combines multiple sequences into a single sequence by concatenating their elements.
Declaration
public static IEnumerable<T> Joint<T>(this IEnumerable<IEnumerable<T>> collections)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<IEnumerable<T>> | collections | An enumerable collection of sequences whose elements are to be concatenated into a single sequence. Cannot be null. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumerable sequence containing all elements from the input sequences, in the order they appear. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the elements contained in the input sequences. |
Remarks
This method flattens a collection of collections into a single sequence, making it easier to iterate over all elements. The order of elements in the resulting sequence matches the order in the input collections.
Locked<T>(T, Action<T>)
Executes an operation on a sequence in a locked context.
Declaration
public static void Locked<T>(this T collection, Action<T> action) where T : IEnumerable
Parameters
| Type | Name | Description |
|---|---|---|
| T | collection | Sequence on which to execute a locked operation. |
| Action<T> | action | Action to execute on the sequence. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements in the sequence. |
Locked<T, TResult>(T, Func<T, TResult>)
Executes an operation on a sequence in a locked context.
Declaration
public static TResult Locked<T, TResult>(this T collection, Func<T, TResult> function) where T : IEnumerable
Parameters
| Type | Name | Description |
|---|---|---|
| T | collection | Sequence on which to execute a locked operation. |
| Func<T, TResult> | function | Function to execute on the sequence. |
Returns
| Type | Description |
|---|---|
| TResult |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements in the sequence. |
| TResult | Type of result obtained by the function. |
NonDefaults<T>(IEnumerable<T?>)
Enumerates the elements that are distinct from their default value within a collection.
Declaration
public static IEnumerable<T> NonDefaults<T>(this IEnumerable<T?> collection) where T : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Collection to enumerate. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumeration with the elements of the collection, omitting those that are equal to their default value, or in the case of reference types, omitting those that are null. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements in the collection. |
NotNull(IEnumerable?)
Enumerates the non-null elements of a collection.
Declaration
public static IEnumerable NotNull(this IEnumerable? collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | collection | Collection to enumerate. |
Returns
| Type | Description |
|---|---|
| IEnumerable | An enumeration with the elements of the collection, omitting
those that are null, or a collection empty if
|
NotNull<T>(IEnumerable<T?>?)
Enumerates the non-null elements of a collection.
Declaration
public static IEnumerable<T> NotNull<T>(this IEnumerable<T?>? collection) where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T?> | collection | Collection to enumerate. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumeration with the non-null elements of the collection, or an
empty collection if |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements in the collection. |
NotNull<T>(IEnumerable<T?>?)
Enumerates the non-null elements of a collection.
Declaration
public static IEnumerable<T> NotNull<T>(this IEnumerable<T?>? collection) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Collection to enumerate. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumeration with the non-null elements of the collection, or an
empty collection if |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements in the collection. |
NullCount(IEnumerable)
Gets the count of null elements within a sequence.
Declaration
public static int NullCount(this IEnumerable collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | collection | Sequence from which to get the count of null elements. |
Returns
| Type | Description |
|---|---|
| int | The count of null elements within the collection. |
OfType<T>(IEnumerable<T>, Type)
Enumerates all elements of the collection that are of the specified type.
Declaration
public static IEnumerable<T> OfType<T>(this IEnumerable<T> collection, Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Collection over which to perform the search. |
| Type | type | Type of elements to return. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumeration of all elements of the collection that are of the specified type. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the collection. |
OrNull<T>(IEnumerable<T>)
Enumerates the collection, and returns null if the collection contains no elements.
Declaration
public static IEnumerable<T>? OrNull<T>(this IEnumerable<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Collection to enumerate. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumeration with the elements of the collection, or null if the collection contains no elements. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements in the collection. |
Ordered<T>(IEnumerable<T>)
Iterates in sorted order over the collection.
Declaration
public static IOrderedEnumerable<T> Ordered<T>(this IEnumerable<T> collection) where T : IComparable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Collection to iterate over |
Returns
| Type | Description |
|---|---|
| IOrderedEnumerable<T> | An ordered enumerable object created from the collection. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements in the collection. |
PickAsync<T>(IEnumerable<T>)
Selects a random element from the collection asynchronously.
Declaration
public static Task<T> PickAsync<T>(this IEnumerable<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection |
Returns
| Type | Description |
|---|---|
| Task<T> | A random object from the collection. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the IEnumerable<T>. |
Pick<T>(IEnumerable<T>)
Selects a random element from the collection.
Declaration
public static T Pick<T>(this IEnumerable<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Collection from which to select. |
Returns
| Type | Description |
|---|---|
| T | A random object from the collection. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the IEnumerable<T>. |
Pick<T>(IEnumerable<T>, in Random)
Selects a random element from the collection.
Declaration
public static T Pick<T>(this IEnumerable<T> collection, in Random random)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Collection from which to select. |
| Random | random | Random number generator to use. |
Returns
| Type | Description |
|---|---|
| T | A random object from the collection. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the IEnumerable<T>. |
Quorum<T>(IEnumerable<T>, int)
Determines the most frequently occurring value in the provided collection that meets the specified quorum count.
Declaration
public static T Quorum<T>(this IEnumerable<T> values, int quorumCount) where T : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | values | The collection of values to evaluate. Cannot be null. |
| int | quorumCount | The minimum number of occurrences required for a value to be considered a quorum. |
Returns
| Type | Description |
|---|---|
| T | The value that meets the quorum count and occurs most frequently in the collection. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the values in the collection. Must be a non-nullable type. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if no value in the collection meets the specified quorum count. |
Range<T>(IEnumerable<T>, int, int)
Gets a sub-range of values within this IEnumerable<T>.
Declaration
public static IEnumerable<T> Range<T>(this IEnumerable<T> from, int index, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | from | IEnumerable<T> from which to extract the sequence. |
| int | index | Index from which to obtain the sub-range. |
| int | count | Quantity of elements to obtain. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An IEnumerable<T> that contains the specified sub-range. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException | Thrown if |
Rotate<T>(IEnumerable<T>, int)
Rotates the elements of an array, list, or collection.
Declaration
public static IEnumerable<T> Rotate<T>(this IEnumerable<T> collection, int steps)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Array to rotate |
| int | steps | Direction and units of rotation. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the IEnumerable<T>. |
Remarks
If steps is positive, the rotation occurs upwards; otherwise, downwards.
SelectAsync<TIn, TOut>(IEnumerable<TIn>, Func<TIn, Task<TOut>>)
Transforms an input enumeration to the required output type asynchronously.
Declaration
public static IAsyncEnumerable<TOut> SelectAsync<TIn, TOut>(this IEnumerable<TIn> input, Func<TIn, Task<TOut>> selector)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TIn> | input | Input enumeration. |
| Func<TIn, Task<TOut>> | selector | Asynchronous task that will transform the input data. |
Returns
| Type | Description |
|---|---|
| IAsyncEnumerable<TOut> | An IAsyncEnumerable<T> that can be used to await the enumeration of each element. |
Type Parameters
| Name | Description |
|---|---|
| TIn | Type of elements in the input enumeration. |
| TOut | Type of elements in the output enumeration. |
Shift<T>(IEnumerable<T>, int)
Shifts the elements of an array, list, or collection.
Declaration
public static IEnumerable<T> Shift<T>(this IEnumerable<T> collection, int steps)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Array to shift |
| int | steps | Direction and units of shift. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the IEnumerable<T>. |
Remarks
If steps is positive, the shift occurs upwards; otherwise, downwards.
Shuffled<T>(IEnumerable<T>)
Returns an unsorted version of the IEnumerable<T> without altering the original collection.
Declaration
public static IEnumerable<T> Shuffled<T>(this IEnumerable<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | IEnumerable<T> to shuffle. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An unsorted version of the IEnumerable<T>. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the IEnumerable<T>. |
Shuffled<T>(IEnumerable<T>, in int)
Returns an unsorted version of the IEnumerable<T> without altering the original collection.
Declaration
public static IEnumerable<T> Shuffled<T>(this IEnumerable<T> collection, in int deepness)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | IEnumerable<T> to shuffle. |
| int | deepness | Depth of the shuffle. 1 is the highest. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An unsorted version of the IEnumerable<T>. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the IEnumerable<T>. |
Shuffled<T>(IEnumerable<T>, in int, in int)
Returns an unsorted version of the specified range of elements of the IEnumerable<T> without altering the original collection.
Declaration
public static IEnumerable<T> Shuffled<T>(this IEnumerable<T> collection, in int firstIdx, in int lastIdx)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | IEnumerable<T> to shuffle. |
| int | firstIdx | Starting index of the range. |
| int | lastIdx | Starting index of the range. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An unsorted version of the specified range of elements of the IEnumerable<T>. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the IEnumerable<T>. |
Shuffled<T>(IEnumerable<T>, in int, in int, in int, in Random)
Returns an unsorted version of the specified range of elements of the IEnumerable<T> without altering the original collection.
Declaration
public static IEnumerable<T> Shuffled<T>(this IEnumerable<T> collection, in int firstIdx, in int lastIdx, in int deepness, in Random random)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | IEnumerable<T> to shuffle. |
| int | firstIdx | Starting index of the range. |
| int | lastIdx | Starting index of the range. |
| int | deepness | Depth of the shuffle. 1 is the highest. |
| Random | random | Random number generator to use. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An unsorted version of the specified range of elements of the IEnumerable<T>. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements contained in the IEnumerable<T>. |
Slice<T>(IEnumerable<T>, int)
Splits the specified collection into a specified number of slices.
Declaration
public static IEnumerable<IEnumerable<T>> Slice<T>(this IEnumerable<T> collection, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | The collection to be sliced. |
| int | count | The number of slices to create. |
Returns
| Type | Description |
|---|---|
| IEnumerable<IEnumerable<T>> | An enumerable of slices, where each slice is an enumerable of elements from the original collection. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of elements in the collection. |
Remarks
The elements are distributed among slices in a way that tries to make the slices as evenly sized as possible. If the collection length is not evenly divisible by the slice count, the remaining elements are distributed among the slices from left to right.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Sum(IEnumerable<TimeSpan>)
Calculates the total duration by summing all TimeSpan values in the collection.
Declaration
public static TimeSpan Sum(this IEnumerable<TimeSpan> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TimeSpan> | collection |
Returns
| Type | Description |
|---|---|
| TimeSpan | A TimeSpan representing the total duration of all elements in the collection. Returns Zero if the collection is empty. |
ToExtendedListAsync<T>(IEnumerable<T>)
Creates a ListEx<T> from an IEnumerable<T> asynchronously.
Declaration
[Obsolete("The class is not supported by MCART anymore.")]
public static Task<ListEx<T>> ToExtendedListAsync<T>(this IEnumerable<T> enumerable)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | enumerable |
Returns
| Type | Description |
|---|---|
| Task<ListEx<T>> | A task that can be used to monitor the operation. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the collection. |
ToExtendedList<T>(IEnumerable<T>)
Creates a ListEx<T> from an IEnumerable<T>.
Declaration
[Obsolete("The class is not supported by MCART anymore.")]
public static ListEx<T> ToExtendedList<T>(this IEnumerable<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | Collection to convert |
Returns
| Type | Description |
|---|---|
| ListEx<T> | A ListEx<T> from the TheXDS.MCART.Types.Extensions namespace. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the collection. |
ToGeneric(IEnumerable)
Enumerates a non-generic collection as a generic one.
Declaration
public static IEnumerable<object?> ToGeneric(this IEnumerable collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable | collection | Collection to enumerate. |
Returns
| Type | Description |
|---|---|
| IEnumerable<object> | An enumeration with the contents of the non-generic enumeration exposed as a generic one. |
ToListAsync<T>(IEnumerable<T>)
Creates a List<T> from an IEnumerable<T> asynchronously.
Declaration
public static Task<List<T>> ToListAsync<T>(this IEnumerable<T> enumerable)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | enumerable |
Returns
| Type | Description |
|---|---|
| Task<List<T>> | A task that can be used to monitor the operation. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the collection. |
YieldAsync<T>(IEnumerable<T>, Func<T, Task>)
Executes a task asynchronously over each item to be enumerated.
Declaration
public static IAsyncEnumerable<T> YieldAsync<T>(this IEnumerable<T> input, Func<T, Task> processor)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | input | Input enumeration. |
| Func<T, Task> | processor | Asynchronous task that will be executed over each item before being enumerated. |
Returns
| Type | Description |
|---|---|
| IAsyncEnumerable<T> | An IAsyncEnumerable<T> that can be used to await the enumeration of each element. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of elements in the enumeration. |