In This Article

Int32Extensions Class

Provides extension methods for the int type.

public static class Int32Extensions
Inheritance:
object object

Methods

ClampToNonnegative(int)

Clamps a value to nonnegative number between 0..MaxValue.

public static int ClampToNonnegative(this int value)
Parameter Type Description
value int

The value to examine.

Returns

int:

The clamped value.

ClampToRange(int, int, int)

Clamps a value between the specified minimum and maximum.

public static int ClampToRange(this int value, int minimum, int maximum)
Parameter Type Description
value int

The value to examine.

minimum int

The minimum value.

maximum int

The maximum value.

Returns

int:

The clamped value.

IsBetween(int, int, int, bool)

Returns whether a value is between the specified minimum and maximum.

public static bool IsBetween(this int value, int minimum, int maximum, bool isInclusive = true)
Parameter Type Description
value int

The value to examine.

minimum int

The number that the value must be greater than, or equal to if inclusive.

maximum int

The number that the value must be less than, or equal to if inclusive.

isInclusive bool

Whether the check considers minimum and maximum as being inclusive. The default value is true.

Returns

bool:

true if the value is between the specified minimum and maximum; otherwise, false.

IsEven(int)

Returns whether the value is an even number.

public static bool IsEven(this int value)
Parameter Type Description
value int

The value to examine.

Returns

bool:

true if the value is an even number; otherwise, false.

IsNonnegative(int)

Returns whether a value is inclusively between 0..MaxValue.

public static bool IsNonnegative(this int value)
Parameter Type Description
value int

The value to examine.

Returns

bool:

true if the value is inclusively between 0..MaxValue; otherwise, false.

IsOdd(int)

Returns whether the value is an odd number.

public static bool IsOdd(this int value)
Parameter Type Description
value int

The value to examine.

Returns

bool:

true if the value is an odd number; otherwise, false.

IsPositive(int)

Returns whether a value is inclusively between 1..MaxValue.

public static bool IsPositive(this int value)
Parameter Type Description
value int

The value to examine.

Returns

bool:

true if the value is inclusively between 1..MaxValue; otherwise, false.

RoundToMultiple(int, int)

Returns a number rounded to the nearest multiple of another number.

public static int RoundToMultiple(this int value, int multipleOf)
Parameter Type Description
value int

The value to round.

multipleOf int

The number that defines the multiple.

Returns

int:

A number rounded to the nearest multiple of another number.

Inherited Members