ComparableIntervals 2.0.0

.NET Standard 2.0 .NET Framework 4.0
Install-Package ComparableIntervals -Version 2.0.0
dotnet add package ComparableIntervals --version 2.0.0
<PackageReference Include="ComparableIntervals" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ComparableIntervals --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ComparableIntervals, 2.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install ComparableIntervals as a Cake Addin
#addin nuget:?package=ComparableIntervals&version=2.0.0

// Install ComparableIntervals as a Cake Tool
#tool nuget:?package=ComparableIntervals&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.


A library which helps doing common operations, such as union, intersection or complement, on intervals of IComparable types.

Disclaimer: I've created this library for a very specific application I'm developing in my company. I've tried to make it more generic than I needed, but eventually it may be not as generic as it should be. If this library fits your needs, you're welcome to use it, but if you need more functionalities, please don't ask for them. In any case, any pull request is appreciated.

Getting started

Every method and class in this library is documented inline, but here are a few hints to get started.

Create two Intervals of type int:

var interval1 = Interval<int>.Closed(1, 5);
var interval2 = Interval<int>.Open(3, 7);

Perform some operations on them:

var intersection = interval1.Intersection(interval2); // => (3, 5]
var Union = interval1.Union(interval2); // => [1, 7)

Perform operations on lists of intervals:

var intervals1 = new List<Interval<int>> {
    Interval<int>.ClosedOpen(-2, 2),
    Interval<int>.OpenClosed(4, 8)
var intervals2 = new List<Interval<int>> {
    Interval<int>.Closed(0, 6),

var intersection = Intervals.Intersection(intervals1, intervals2); // => [0, 2), (4, 6]
var union = Intervals.Union(intervals1, intervals2); // => [-2, 8]
var complement = Intervals.Complement(intervals1); // => (-∞, -2), [2, 4], (8, ∞)

Library structure

This library library exposes a few objects to build and compute intervals.

struct Bound<T>: represents a bound of type T, where T : IComparable. A bound may be open, closed, or may represent negative or positive infinity. Methods to create those types of bounds are provided.

class Interval<T>: represents an interval of type T, where T : IComparable. An interval is an entity with an upper bound and a lower bound. To create a closed, open, open-close, closed-open interval, one of the provided methods may be used, otherwise it can be created providing its bounds. Operations on an interval (such as union and intersection) are provided as extension methods, so that they can be called on an instance of an interval or in a static way.

static class Intervals: a class which provides static methods to operate on collections of intervals.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .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.7.2

    • No dependencies.
  • .NETStandard 2.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
2.0.0 300 9/16/2020