ArrayExtensions
Comprehensive collection of 245 extension methods for C# arrays. Also available as NuGet package.
Install / Use
/learn @Tim-Maes/ArrayExtensionsREADME
ArrayExtensions
A comprehensive collection of extension methods for arrays in C#.
Index
- Generic Array Methods (44 methods)
- DateTime Array Methods (31 methods)
- String Array Methods (43 methods
- Integer Array Methods (33 methods)
- Double Array Methods (20 methods)
- Boolean Array Methods (24 methods)
- Character Array Methods (29 methods)
- Byte Array Methods (26 methods)
- GUID Array Methods (22 methods)
- Multi-Dimensional Array Methods (12 methods)
Installation :wrench:
Install via NuGet:
Install-Package ArrayExtensions
Or just copy whatever you need from this repository :)
Usage
var result = array.MethodName();
Features :star:
Generic Array methods
| Name | Description |
|---------------------------------------------------|---------------------------------------------------------------------------|
| Add<T>(), AddRange<T>() | Appends single or multiple items to the end of an array. |
| AllEqual<T>() | Checks if all elements in an array are identical. |
| AnyNull<T>() | Determines if any element in an array of reference types is null. |
| BinarySearch<T>() | Performs a binary search on a sorted array. |
| Chunk<T>() | Divides an array into smaller arrays of a specified maximum size. |
| Contains<T>() | Checks if the array contains a specified element. |
| CountOf<T>() | Counts occurrences of a specific item in the array. |
| DeepCopy<T>() | Creates a deep copy of an array, where elements implement ICloneable. |
| DistinctBy<T, TKey>() | Returns distinct elements based on a specified selector function. |
| DistinctValues<T>() | Returns distinct values from the array. |
| FindFirstAndLast<T>() | Finds the first and last elements that match a given predicate. |
| FindIndices<T>() | Finds indices of all elements that match a given predicate. |
| FindOrDefault<T>() | Finds an element matching a predicate, or returns a default value. |
| Flatten<T>() | Flattens a multi-dimensional array into a single-dimensional array. |
| ForEach<T>() | Executes an action on each element of an array. |
| ForEachIndexed<T>() | Executes an action on each element of an array with its index. |
| GroupBySequential<T, TKey>() | Groups adjacent elements sharing a key or property. |
| Head<T>(), Tail<T>(), LastN<T>(), FirstN<T>() | Provide various ways to slice and access elements. |
| Interleave<T>() | Interleaves elements of two arrays into a single array. |
| InsertAt<T>() | Inserts an element at a specified index. |
| IsNullOrEmpty<T>(), IsEmpty<T>() | Check if an array is empty or null/empty, respectively. |
| IsSorted<T>() | Checks if the array is sorted according to a specified comparer. |
| IsUnique<T>() | Determines whether all elements in the array are unique. |
| JoinToString<T>() | Concatenates string representations of elements with a delimiter. |
| Map<T, TResult>() | Transforms each element of the array using a selector function. |
| MaxBy<T, TKey>(), MinBy<T, TKey>() | Finds the maximum/minimum element based on a specified selector function. |
| MostCommon<T>() | Finds the most common element in the array. |
| Permute<T>() | Generates all possible permutations of the array. |
| RandomSample<T>() | Selects a random sample of elements. |
| RemoveAt<T>() | Removes the element at a specified index. |
| RemoveDuplicates<T>() | Removes duplicate elements from the array. |
| RemoveNulls<T>() | Removes all null items from an array of reference types. |
| ReplaceAll<T>() | Replaces all occurrences of a specific value with another in the array. |
| Resize<T>() | Resizes an array to a specified new size. |
| Reverse<T>() | Reverses the elements of the array. |
| RotateLeft<T>(), RotateRight<T>() | Rotates the array left or right by a specified number of positions. |
| SafeGet<T>() | Retrieves an element at a specified index or a default value if out of range. |
| SafeSet<T>() | Sets a value at a specified index, resizing the array if necessary. |
| Segment<T>() | Splits an array into segments based on a predicate. |
| SequentialPairs<T>() | Generates a sequence of tuples from sequential pairs of elements. |
| Shuffle<T>() | Randomly shuffles the elements of an array. |
| Slice<T>() | Returns a portion of the array, similar to substring for strings. |
| Subset<T>() | Returns all possible subsets of the array. |
| SumBy<T>() | Calculates the sum of array elements based on a selector function. |
| TakeWhile<T>(), SkipWhile<T>() | Takes or skips elements of the array while a condition is true. |
| ToHashSet<T>() | Converts the array to a HashSet, removing duplicates. |
| ZipWith<T, TOther, TResult>() | Combines two arrays into one using a specified selector function. |
DateTime Array methods
|Name | Description |
|-----------------------------------|---------------------------------------------------|
|AllInFuture| Checks if all dates in the array are in the future.|
|AllInPast| Checks if all dates in the array are in the past.|
|AverageTimeBetweenDates| Calculates the average time span between consecutive dates (when sorted).|
|BusinessDaysCount| Calculates the number of business days between the earliest and latest date in the array.|
|CalculateAges| Calculates ages (in years) for all dates relative to a reference date.|
|ClosestTo| Gets the closest date to a specified reference date.|
|DateRange| Gets the range between the earliest and latest date.|
|EarliestDate| Finds and returns the earliest date present in the array.|
|EquidistantDates| Finds dates that are equidistant from a given reference date.|
|FilterByDateRange| Filters dates that fall within a specified date range.|
|FilterByDecade| Filters dates that fall within a specific decade.|
|FilterByQuarter| Filters dates that fall within a specific quarter of any year.|
|FilterBySeason| Filters dates that fall within a specific season in the Northern Hemisphere.|
|FilterHolidays| Filters dates that match a provided list of holidays.|
|FilterLastDayOfWeek| Filters dates that fall on the last specific day of the week of their month.|
|FilterNthDayOfWeek| Filters dates that are the nth occurrence of a specified day of the week in their month.|
|FilterWeekdays| Filters dates that are weekdays (Monday to Friday).|
|FilterWeekends| Filters dates that are weekends (Saturday or Sunday).|
|FindBirthdays| Finds dates that are birthdays (same month and day) for a given reference date.|
|FindMaximumGap| Finds the dates with the maximum gap between consecutive dates.|
|GroupByDay| Groups dates by day.|
|GroupByDayOfWeek| Groups dates by their day of the week.|
|GroupByMonth| Groups dates by month.|
|GroupByQuarter| Groups dates by quarter of the year.|
|GroupByTimePeriod| Groups dates by time of day periods.|
|GroupByYear| Groups dates by year.|
|LatestDate| Finds and returns the latest date present in the array.|
|RoundTo| Rounds all dates to the nearest specified time unit.|
|SortChronologically| Sorts the dates in chronological order (earliest to latest).|
|SortReverseChronologically| Sorts the dates in reverse chronological order (latest to earliest).|
|ToLocalTime| Converts all dates to local timezone.|
|ToUtc| Converts all dates to UTC timezone.|
String Array methods
|Name
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
