Enumerable Tools
Enumerable tools to help you manipulate with them!
Enumerable extensions can be found in the EnumerableExtensions
static class that is found under the Magico.Enumeration
namespace. You don't have to explicitly reference the class, because you can just place a dot after the IEnumerable
instance.
Length()
Length()
public static int Length(this IEnumerable enumerable)
This extension counts the elements inside this enumerable class instance, and it's adaptive to several enumerable types for performance, as in:
Arrays
Lists
Dictionaries
Collections
Non-generic
IEnumerable
instances
GetElementFromIndex()
GetElementFromIndex()
public static object? GetElementFromIndex(this IEnumerable enumerable, int index)
Gets an element using the index number from the enumerable that is either generic or non-generic. It's adaptive to several enumerable types for performance, as in:
Arrays
Lists
Dictionaries
Collections
Non-generic
IEnumerable
instances
Zip()
Zip()
public static IEnumerable<(TFirst First, TSecond Second)> Zip<TFirst, TSecond>(
this IEnumerable<TFirst> source, IEnumerable<TSecond> second)
This extension merges two generic IEnumerable
instances into one.
ToDictionarySafe()
ToDictionarySafe()
public static Dictionary<TKey, TValue> ToDictionarySafe<TSource, TKey, TValue>(
this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> valueSelector)
where TKey : notnull
This extension converts the source enumerable instance of the source type to a dictionary that is of a selected key type and value type. This ensures safe conversion.
Last updated