Skip to content

Long Extensions

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

UtilityLibrary.Core

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

PercentageOf

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

Abs

Abs

Returns the absolute value of the given long value.

using UtilityLibrary.Core;

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

Parameters

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

Returns

  • long: The absolute value of the long value.

Abs (IEnumerable)

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

Parameters

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

Returns

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

Range

IsInRange

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

Parameters

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

Returns

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

InRange

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

Parameters

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

Returns

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

Odd / Even

IsEven

Determines whether a long value is an even number.

using UtilityLibrary.Core;

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

Parameters

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

Returns

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

IsOdd

Determines whether a long value is an odd number.

using UtilityLibrary.Core;

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

Parameters

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

Returns

  • bool: True if the long value is an odd number; otherwise, False.

Clone this wiki locally