Skip to content

IComparable extension methods

Alex Kamsteeg edited this page Aug 8, 2015 · 1 revision

Overview

SwissArmyKnife adds the following extension methods to IComparable<T>:

IsBetween()

The IsBetween() extension method makes it easier to determine whether a value falls within a range or not. Without it you have to write the following code:

var example = 2;

if (example >= 1 && example <= 3)
{
   // do something
}

IsAnyOf() shortens this to:

var example = 2;

if (example.IsBetween(1,3))
{
   // do something
}

Clone this wiki locally