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