IsEven 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package IsEven --version 3.0.0                
NuGet\Install-Package IsEven -Version 3.0.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="IsEven" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IsEven --version 3.0.0                
#r "nuget: IsEven, 3.0.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 IsEven as a Cake Addin
#addin nuget:?package=IsEven&version=3.0.0

// Install IsEven as a Cake Tool
#tool nuget:?package=IsEven&version=3.0.0                

IsEven

A robust, extensible, and blue-sky-thinking .NET library for calculating if an integer is even.

In a rapidly-changing technology landscape where the demystification of number even-ness is mission-critical, this may be the game-changer for facing into your organisational arithmetic delivery.

Examples

IsEvenCalculator

Use the IsEvenCalculator to determine the even-ness of your number, using Modulo division by default:

bool isEven = IsEvenCalculator.IsEven(2);
bool isOdd = IsEvenCalculator.IsOdd(5);

An 'AlgorithmType' argument may optionally be supplied to specify the algorithm to use when calculating whether a number is even:

bool isEven = 2.IsEven(AlgorithmType.LastDigitCheck);

Sometimes you may be unsure if you have a number that is odd or even - the below will alleviate all doubt:

bool isOddOrEven = 2.IsOddOrEven();
bool isOddOrEven = IsEvenCalculator.IsOddOrEven(2);

Extension Methods

You may face into the below extension methods, adding further strings to your strategical enterprise bow:

bool isEven = 2.IsEven();
bool isOdd = 5.IsOdd();
bool isOddOrEven = 6.IsOddOrEven();

Client

You may also use the IsEvenClient, underpinned by the helpful IIsEvenClient interface, pivoting into dependency injection and mocking opportunities.

IIsEvenClient isEvenClient = new IsEvenClient();

bool isEven = isEvenClient.IsEven(2);
bool isOdd = isEvenClient.IsEven(3);
bool isOddOrEven = isEvenClient.IsOddOrEven(4);

Abstraction Layers

Take the standard Modulo division algorithm to calculate if a number is even:

return n % 2 == 0;

This is:

  • Far too easy to read
  • Overly maintainable
  • The top answer on StackOverflow

Allowing needlessly readable logic such as this to run amock in your enterprise codebase would not be proper; thus, multiple abstracted layers - sensibly distributed across multiple files - have been added to this library to support possible future requirements.

These layers include:

  • Optional algorithm types being specified which may be slower, such as checking the last digit of the number, using Math.DivRem, or bit-shifting, as examples
  • Extensibility of the name of numbers, in case they are fundamentally changed in future
  • Abstraction of whether 0 should be considered even or not, to avoid any arguments

Dependencies

This library does not include dependencies to avoid additional architectural sign-off, keeping the discussions about introducing this library confined to only a handful of solution assessment boards.

Product 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.

Version Downloads Last updated
5.0.0 111 7/18/2024
4.0.0 170 9/27/2023
3.0.0 178 5/13/2023
2.0.0 436 8/18/2022
1.0.0 408 8/4/2022