InRange 1.0.0
dotnet add package InRange --version 1.0.0
NuGet\Install-Package InRange -Version 1.0.0
<PackageReference Include="InRange" Version="1.0.0" />
<PackageVersion Include="InRange" Version="1.0.0" />
<PackageReference Include="InRange" />
paket add InRange --version 1.0.0
#r "nuget: InRange, 1.0.0"
#:package InRange@1.0.0
#addin nuget:?package=InRange&version=1.0.0
#tool nuget:?package=InRange&version=1.0.0
![]()
InRange
Lightweight C# extension library for checking if an index is within the valid range of arrays and collections. This repository provides extension methods for IEnumerable<T>, ICollection<T>, IList<T>, IQueryable<T>, arrays (including multi-dimensional), and a static helper for index validation.
Project layout
src/InRangeExtension.cs- core extension methods for index range checking on collections and arrayssrc/InRangeExtension.WithInRange.cs- fluent-styleWithInRangeextension methods (including multi-dimensional arrays)src/InRangeExtension.CheckInRange.cs-CheckInRangeextension methods that throw on out-of-rangetests/- unit tests (System.InRange.Tests)
Namespace and public types
- Namespace:
System.InRange - Static class:
InRangeExtension - Key methods (overview):
bool InRange(this IEnumerable<T> source, int index)bool InRange(this ICollection<T> source, int index)bool InRange(this IList<T> source, int index)bool InRange(this IQueryable<T> source, int index)bool InRange(this T[] source, int index)bool InRange(this T[,] source, int i, int j)bool InRange(this T[,,] source, int i, int j, int k)bool InRange(int index, int? count)TSource WithInRange(..., out bool result)(all above types, including multi-dimensional arrays)void CheckInRange(...);(all above types, throws on out-of-range)
Behavior and features
- Returns
trueif the index is within[0, source.Count); otherwise, returnsfalse - Handles
nullcollections gracefully (returnsfalse) - Supports all major .NET collection interfaces and arrays, including multi-dimensional arrays
- Compatible with a wide range of .NET targets (see below)
- Aggressive inlining for performance on supported platforms
- Performance Note: For
IEnumerable<T>andIQueryable<T>, callingCount()will enumerate the entire collection if it does not implementICollection<T>,IReadOnlyCollection<T>, or similar. For best performance, prefer using overloads forICollection<T>,IReadOnlyCollection<T>,IList<T>,IReadOnlyList<T>,List<T>, or arrays whenever possible.
Examples
using System.InRange;
var arr = new[] { 10, 20, 30 };
bool valid = arr.InRange(1); // true
bool invalid = arr.InRange(3); // false
IList<string> list = new List<string> { "a", "b" };
bool validList = list.InRange(0); // true
IEnumerable<int> enumerable = new List<int> { 1, 2, 3 };
bool validEnum = enumerable.InRange(2); // true
IQueryable<int> queryable = enumerable.AsQueryable();
bool validQueryable = queryable.InRange(1); // true
// Multi-dimensional arrays
int[,] arr2d = new int[3, 2];
bool valid2d = arr2d.InRange(2, 1); // true
bool invalid2d = arr2d.InRange(3, 0); // false
// Fluent WithInRange usage
arr.WithInRange(1, out var ok1); // returns arr, ok1 == true
arr2d.WithInRange(2, 1, out var ok2d); // returns arr2d, ok2d == true
// Throws if out of range
arr.CheckInRange(1); // ok
// arr.CheckInRange(3); // throws ArgumentOutOfRangeException
bool staticValid = InRangeExtension.InRange(0, 3); // true
bool staticInvalid = InRangeExtension.InRange(3, 3); // false
Supported target frameworks
The project in src/System.InRange.csproj is multi-targeted and aims to be widely compatible. The repository includes support for many targets (examples):
- .NET Standard 1.0 → 2.1
- .NET Framework 3.5 → 4.8.1
- .NET Core 1.0 → 3.1
- .NET 5 → 10
Pick the appropriate target when referencing the library.
Build and test
Requires the .NET SDK. Recommended: .NET 7 or later.
From the repository root:
dotnet restore
dotnet build
dotnet test
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. 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 is compatible. 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 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. |
| .NET Core | netcoreapp1.0 is compatible. netcoreapp1.1 is compatible. netcoreapp2.0 is compatible. netcoreapp2.1 is compatible. netcoreapp2.2 is compatible. netcoreapp3.0 is compatible. netcoreapp3.1 is compatible. |
| .NET Standard | netstandard1.0 is compatible. netstandard1.1 is compatible. netstandard1.2 is compatible. netstandard1.3 is compatible. netstandard1.4 is compatible. netstandard1.5 is compatible. netstandard1.6 is compatible. netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net35 is compatible. net40 is compatible. net403 was computed. net45 is compatible. net451 is compatible. net452 is compatible. net46 is compatible. net461 is compatible. net462 is compatible. net463 was computed. net47 is compatible. net471 is compatible. net472 is compatible. net48 is compatible. net481 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
| Universal Windows Platform | uap was computed. uap10.0 was computed. |
| Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
| Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 1.0
- Microsoft.NETCore.App (>= 1.0.5)
-
.NETCoreApp 1.1
- Microsoft.NETCore.App (>= 1.1.2)
-
.NETCoreApp 2.0
- No dependencies.
-
.NETCoreApp 2.1
- No dependencies.
-
.NETCoreApp 2.2
- No dependencies.
-
.NETCoreApp 3.0
- No dependencies.
-
.NETCoreApp 3.1
- No dependencies.
-
.NETFramework 3.5
- No dependencies.
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.5.1
- No dependencies.
-
.NETFramework 4.5.2
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.6.1
- No dependencies.
-
.NETFramework 4.6.2
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETFramework 4.7.1
- No dependencies.
-
.NETFramework 4.7.2
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETFramework 4.8.1
- No dependencies.
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.1
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.2
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.4
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.5
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.6
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.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.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 74 | 1/14/2026 |