-
Notifications
You must be signed in to change notification settings - Fork 0
Int Extensions
This utility library provides extension methods for integer values to perform various operations.
Calculates the percentage of a int value relative to another int value.
int part = // initialize your int value;
int whole = // initialize your int value;
float percentage = part.PercentageOf(whole);Parameters:
-
part: The int value for which the percentage is calculated. -
whole: The int value representing the whole or total.
Returns:
-
percentage: Afloatvalue representing the percentage of thepartrelative to thewhole.
Clamps the integer value to a minimum of 0.
using UtilityLibrary.Core;
int value = -5;
int result = value.ClampMin0();-
value(int): The integer value to clamp.
- int: The clamped value with a minimum of 0.
Clamps the integer value to a specified minimum.
using UtilityLibrary.Core;
int value = -5;
int min = 0;
int result = value.ClampMin(min);-
value(int): The integer value to clamp. -
min(int): The minimum value to clamp to.
- int: The clamped value with a minimum of the specified value.
Clamps the integer value to a maximum of 0.
using UtilityLibrary.Core;
int value = 5;
int result = value.ClampMax0();-
value(int): The integer value to clamp.
- int: The clamped value with a maximum of 0.
Clamps the integer value to a specified maximum.
using UtilityLibrary.Core;
int value = 15;
int max = 10;
int result = value.ClampMax(max);-
value(int): The integer value to clamp. -
max(int): The maximum value to clamp to.
- int: The clamped value with a maximum of the specified value.
Clamps the integer value to the range [0, 1].
using UtilityLibrary.Core;
int value = 5;
int result = value.Clamp01();-
value(int): The integer value to clamp.
- int: The clamped value within the range [0, 1].
Clamps the integer value within a specified range.
using UtilityLibrary.Core;
int value = 15;
int min = 10;
int max = 20;
int result = value.Clamp(min, max);-
value(int): The integer value to clamp. -
min(int): The minimum value of the range. -
max(int): The maximum value of the range.
- int: The clamped value within the specified range.
Returns the absolute value of the given integer value.
using UtilityLibrary.Core;
int value = -5;
int absoluteValue = value.Abs();-
value(int): The integer value to calculate the absolute value for.
- int: The absolute value of the integer value.
Returns a sequence of absolute values for each integer value in the given enumerable.
using UtilityLibrary.Core;
IEnumerable<int> values = new List<int> { -5, 10, -3 };
IEnumerable<int> absoluteValues = values.Abs();-
values(IEnumerable): The enumerable containing integer values.
- IEnumerable: A sequence of absolute values for each integer value in the input enumerable.
Determines whether an integer value is within a specified range.
using UtilityLibrary.Core;
int value = 15;
int minValue = 10;
int maxValue = 20;
bool isInRange = value.IsInRange(minValue, maxValue);-
value(int): The integer value to check. -
min(int): The minimum value of the range. -
max(int): The maximum value of the range.
- bool:
Trueif the integer value is within the range; otherwise,False.
Returns the integer value if it is within a specified range; otherwise, returns a default value.
using UtilityLibrary.Core;
int value = 25;
int minValue = 10;
int maxValue = 20;
int defaultValue = -1;
int result = value.InRange(minValue, maxValue, defaultValue);-
value(int): The integer value to check. -
min(int): The minimum value of the range. -
max(int): The maximum value of the range. -
defaultValue(int): The default value to return if the integer value is not within the range.
- int: The integer value if it is within the range; otherwise, the default value.
Determines whether an integer value is an even number.
using UtilityLibrary.Core;
int value = 10;
bool isEven = value.IsEven();-
value(int): The integer value to check.
- bool:
Trueif the integer value is an even number; otherwise,False.
Determines whether an integer value is an odd number.
using UtilityLibrary.Core;
int value = 5;
bool isOdd = value.IsOdd();-
value(int): The integer value to check.
- bool:
Trueif the integer value is an odd number; otherwise,False.
Returns the array index corresponding to the integer value.
using UtilityLibrary.Core;
int value = 3;
int arrayIndex = value.GetArrayIndex();-
value(int): The integer value.
- int: The array index. If the integer value is 0, returns 0; otherwise, returns the integer value.
Determines whether an integer value is a valid index in a specified array.
using UtilityLibrary.Core;
int value = 3;
Array arrayToCheck = new int[5];
bool isValidIndex = value.IsIndexInArray(arrayToCheck);-
value(int): The integer value to check. -
arrayToCheck(Array): The array in which to check the index.
- bool:
Trueif the integer value is a valid index in the array; otherwise,False.