ArrayExtensions 1.1.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ArrayExtensions --version 1.1.0
NuGet\Install-Package ArrayExtensions -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ArrayExtensions" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ArrayExtensions --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ArrayExtensions, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ArrayExtensions as a Cake Addin
#addin nuget:?package=ArrayExtensions&version=1.1.0
// Install ArrayExtensions as a Cake Tool
#tool nuget:?package=ArrayExtensions&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ArrayExtensions
A collection of useful extension methods for arrays in C#.
Features
- ForEach: Execute an action for each item in the array.
- MostCommon: Find the most common item in the array.
- Add Items: Easily append a single item or multiple items to an array.
- All Equal: Check if all items in the array are equivalent.
- DeepCopy: A new array that is a deep copy of the source array.
- Remove/Insert: Remove an item at a specific index or insert one.
- Shuffle: Randomly rearrange the elements of an array.
- Array Checks: Check if the array is empty, or contains any null values.
- Chunking: Break the array into smaller arrays of a specified size.
- LastN: Retrieve the last 'n' items from the array.
- Slice: Returns a portion of the array.
- ReplaceAll: Replace all occurrences of a value in the array.
- Rotate: Rotate the array left or right by a specified number of positions.
- Flatten: Convert a 2D array into a single-dimensional array.
- FindIndices: Find all indices of items that match a given predicate.
- .. and more
Installation
Install via NuGet:
Install-Package ArrayExtensions
Usage
Some examples:
using ArrayExtensions;
string[] fruits = { "apple", "banana", "cherry" };
// Add a single item and multiple items
fruits = fruits.Add("date");
fruits = fruits.AddRange("fig", "grape");
// Insert and remove
fruits = fruits.InsertAt(2, "blueberry");
fruits = fruits.RemoveAt(3); // Removes "cherry"
// Shuffle, check equality and null checks
var shuffledFruits = fruits.Shuffle();
bool allSame = fruits.AllEqual(); // Returns false
bool hasNull = fruits.AnyNull(); // Returns false
// Chunking and replacing
var chunkedFruits = fruits.Chunk(3);
fruits = fruits.ReplaceAll("apple", "apricot");
// Safe retrieval and finding indices
var fruit = fruits.SafeGet(10, "unknown"); // Returns "unknown" as the 10th index doesn't exist
var indices = fruits.FindIndices(f => f.StartsWith("a"));
// ForEach example to print fruits
fruits.ForEach(f => Console.WriteLine(f));
// Extra examples:
string[] fruits = { "apple", "banana", "cherry", "date", "fig", "grape", "blueberry" };
// Check if all items in the array are equal
bool allEqual = fruits.AllEqual(); // Returns false
// Check if any fruit name is empty or null
bool hasEmptyOrNullOrWhiteSpace = fruits.AnyNullOrEmptyOrWhiteSpace(); // Returns false
// Trim all items
string[] trimmedFruits = { " apple ", "banana ", " cherry", " date " };
trimmedFruits = trimmedFruits.TrimAll();
// Find indices of all fruits that start with "b"
int[] bFruitIndices = fruits.FindIndices(f => f.StartsWith("b")); // Returns indices for "banana" and "blueberry"
// Get the first three fruits without creating a new array
string[] firstThree = fruits.Slice(0, 3); // Returns { "apple", "banana", "cherry" }
// Retrieve items in a safe manner
var tenthFruit = fruits.SafeGet(9, "unknown"); // Index 9 doesn't exist, so it returns "unknown"
// Execute an action for each fruit, for example, print them
fruits.ForEach(Console.WriteLine);
// Count occurrences of a particular fruit
int appleCount = fruits.CountOf("apple"); // Returns 1
// Replace all occurrences of a fruit with another
fruits = fruits.ReplaceAll("banana", "mango"); // Replaces "banana" with "mango"
// Get distinct items in the array
var distinctFruits = fruits.DistinctValues();
// Get the most common fruit (or any most common string in an array)
var mostCommonFruit = fruits.MostCommon();
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.