DouglasDwyer.FixedArray
0.1.0
See the version list below for details.
dotnet add package DouglasDwyer.FixedArray --version 0.1.0
NuGet\Install-Package DouglasDwyer.FixedArray -Version 0.1.0
<PackageReference Include="DouglasDwyer.FixedArray" Version="0.1.0" />
<PackageVersion Include="DouglasDwyer.FixedArray" Version="0.1.0" />
<PackageReference Include="DouglasDwyer.FixedArray" />
paket add DouglasDwyer.FixedArray --version 0.1.0
#r "nuget: DouglasDwyer.FixedArray, 0.1.0"
#:package DouglasDwyer.FixedArray@0.1.0
#addin nuget:?package=DouglasDwyer.FixedArray&version=0.1.0
#tool nuget:?package=DouglasDwyer.FixedArray&version=0.1.0
DouglasDwyer.FixedArray
Rust-style fixed-size stack-allocated arrays for C#. Provides Array1<T> through Array32<T> — value types backed by [InlineArray] that live entirely on the stack with no heap allocation.
Installation
dotnet add package DouglasDwyer.FixedArray
The package bundles a Roslyn source generator that emits Array1<T>–Array32<T> into your project at compile time. No runtime dependency is needed beyond the small support types (IFixedArray<T>, FixedArrayEnumerator<T, A>) included in the package.
Usage
Construction
Use C# collection expressions (requires C# 12+):
Array3<int> rgb = [255, 128, 0];
Or use the explicit constructor:
var point = new Array2<float>(1.0f, 2.5f);
Indexing
Each type is an [InlineArray] struct, so standard index syntax works:
Array3<int> v = [10, 20, 30];
int x = v[0];
v[1] = 99;
Enumeration
All array types implement IEnumerable<T>, so foreach and LINQ work out of the box:
Array4<string> words = ["hello", "fixed", "stack", "array"];
foreach (var w in words)
Console.WriteLine(w);
var upper = words.Select(w => w.ToUpper()).ToList();
Equality
Arrays support ==, !=, Equals, and GetHashCode, all compared element-by-element:
Array2<int> a = [1, 2];
Array2<int> b = [1, 2];
Console.WriteLine(a == b); // True
API
| Type | Description |
|---|---|
Array1<T> – Array32<T> |
Stack-allocated fixed-size array structs. |
IFixedArray<T> |
Interface exposing Length and Get(int i), useful for generic constraints. |
FixedArrayEnumerator<T, A> |
Struct enumerator returned by GetEnumerator() — no boxing. |
Requirements
- .NET 8.0 or later
- C# 12 or later (for collection expression syntax)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.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.