Skip to content

Short Extensions

Andrzej Kebab edited this page Feb 4, 2024 · 3 revisions

UtilityLibrary.Core

This utility library provides extension methods for short values to perform various operations.

PercentageOf

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: A float value representing the percentage of the part relative to the whole.

Abs

Abs

Returns the absolute value of the given short value.

using UtilityLibrary.Core;

short value = -5;
short absoluteValue = value.Abs();

Parameters

  • value (short): The short value to calculate the absolute value for.

Returns

  • short: The absolute value of the short value.

Abs (IEnumerable)

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();

Parameters

  • values (IEnumerable): The enumerable containing short values.

Returns

  • IEnumerable: A sequence of absolute values for each short value in the input enumerable.

Range

IsInRange

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);

Parameters

  • value (short): The short value to check.
  • minValue (short): The minimum value of the range.
  • maxValue (short): The maximum value of the range.

Returns

  • bool: True if the short value is within the range; otherwise, False.

InRange

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);

Parameters

  • 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.

Returns

  • short: The short value if it is within the range; otherwise, the default value.

Odd / Even

IsEven

Determines whether a short value is an even number.

using UtilityLibrary.Core;

short value = 10;
bool isEven = value.IsEven();

Parameters

  • value (short): The short value to check.

Returns

  • bool: True if the short value is an even number; otherwise, False.

IsOdd

Determines whether a short value is an odd number.

using UtilityLibrary.Core;

short value = 5;
bool isOdd = value.IsOdd();

Parameters

  • value (short): The short value to check.

Returns

  • bool: True if 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!

Clone this wiki locally