Table of Contents

IntegerExtensions Class

Definition

Namespace
Cuemon.Extensions
Assemblies
Cuemon.Extensions.Core.dll
Source
src/Cuemon.Extensions.Core/IntegerExtensions.cs

Extension methods for the short, int and long structs.

public static class IntegerExtensions
Inheritance
object
IntegerExtensions

Examples

The following example demonstrates how to use the IntegerExtensions extension methods to check whether a given integer is prime, even, or odd, and to find the smallest or largest of two values.

using System;
using Cuemon.Extensions;

namespace MyApp.Examples;

public static class IntegerExtensionsExample
{
    public static void Demonstrate()
    {
        var number = 17;
        bool isPrime = number.IsPrime();
        bool isEven = number.IsEven();
        bool isOdd = number.IsOdd();

        Console.WriteLine(isPrime);
        Console.WriteLine(isEven);
        Console.WriteLine(isOdd);
        Console.WriteLine(5.Max(10));
        Console.WriteLine(15.Min(10));
        Console.WriteLine(500L.Min(1000L));
        Console.WriteLine(((short)3).Max((short)7));
        Console.WriteLine(new[] { 1, 3, 5, 7 }.IsCountableSequence());
    }
}

Methods

Name Description
IsCountableSequence(IEnumerable<int>)

Determines whether the specified source is a sequence of countable integrals (hence, integrals being either incremented or decremented with the same cardinality through out the sequence).

IsCountableSequence(IEnumerable<long>)

Determines whether the specified source is a sequence of countable integrals (hence, integrals being either incremented or decremented with the same cardinality through out the sequence).

IsEven(int)

Determines whether the specified value is an even number.

IsOdd(int)

Determines whether the specified value is an odd number.

IsPrime(int)

Determines whether the specified value is a prime number.

Max(short, short)

Returns the larger of two 16-bit signed integers.

Max(int, int)

Returns the larger of two 32-bit signed integers.

Max(long, long)

Returns the larger of two 64-bit signed integers.

Min(short, short)

Returns the smaller of two 16-bit signed integers.

Min(int, int)

Returns the smaller of two 32-bit signed integers.

Min(long, long)

Returns the smaller of two 64-bit signed integers.