-
Notifications
You must be signed in to change notification settings - Fork 0
Long Extensions
Andrzej Kebab edited this page Feb 4, 2024
·
3 revisions
This utility library provides extension methods for long values to perform various operations.
Calculates the percentage of a long value relative to another long value.
long part = // initialize your long value;
long whole = // initialize your long value;
double percentage = part.PercentageOf(whole);Parameters:
-
part: The long value for which the percentage is calculated. -
whole: The long value representing the whole or total.
Returns:
-
percentage: Adoublevalue representing the percentage of thepartrelative to thewhole.
Returns the absolute value of the given long value.
using UtilityLibrary.Core;
long value = -5;
long absoluteValue = value.Abs();-
value(long): The long value to calculate the absolute value for.
- long: The absolute value of the long value.
Returns a sequence of absolute values for each long value in the given enumerable.
using UtilityLibrary.Core;
IEnumerable<long> values = new List<long> { -5, 10, -3 };
IEnumerable<long> absoluteValues = values.Abs();-
values(IEnumerable): The enumerable containing long values.
- IEnumerable: A sequence of absolute values for each long value in the input enumerable.
Determines whether a long value is within a specified range.
using UtilityLibrary.Core;
long value = 15;
long minValue = 10;
long maxValue = 20;
bool isInRange = value.IsInRange(minValue, maxValue);-
value(long): The long value to check. -
minValue(long): The minimum value of the range. -
maxValue(long): The maximum value of the range.
- bool:
Trueif the long value is within the range; otherwise,False.
Returns the long value if it is within a specified range; otherwise, returns a default value.
using UtilityLibrary.Core;
long value = 25;
long minValue = 10;
long maxValue = 20;
long defaultValue = -1;
long result = value.InRange(minValue, maxValue, defaultValue);-
value(long): The long value to check. -
minValue(long): The minimum value of the range. -
maxValue(long): The maximum value of the range. -
defaultValue(long): The default value to return if the long value is not in the range.
- long: The long value if it is within the range; otherwise, the default value.
Determines whether a long value is an even number.
using UtilityLibrary.Core;
long value = 10;
bool isEven = value.IsEven();-
value(long): The long value to check.
- bool:
Trueif the long value is an even number; otherwise,False.
Determines whether a long value is an odd number.
using UtilityLibrary.Core;
long value = 5;
bool isOdd = value.IsOdd();-
value(long): The long value to check.
- bool:
Trueif the long value is an odd number; otherwise,False.