Table of Contents

Class NH

Namespace
SunamoNumbers
Assembly
SunamoNumbers.dll

Number Helper - provides statistical calculations, interval generation, and numeric utilities.

public static class NH
Inheritance
NH
Inherited Members

Methods

Average(double, double)

Calculates the average of two double values.

public static double Average(double totalValue, double count)

Parameters

totalValue double

The total value (dividend).

count double

The count to divide by (divisor).

Returns

double

AverageFloat(double, double)

Calculates the average of two values and returns the result as float.

public static float AverageFloat(double totalValue, double count)

Parameters

totalValue double

The total value (dividend).

count double

The count to divide by (divisor).

Returns

float

Average<T>(List<T>)

Calculates the average of all values in a list.

public static T Average<T>(List<T> list)

Parameters

list List<T>

The list of values to average.

Returns

T

Type Parameters

T

The numeric type.

Average<T>(dynamic, dynamic)

Calculates the average by dividing the total value by the count.

public static T Average<T>(dynamic totalValue, dynamic count)

Parameters

totalValue dynamic

The total value (dividend).

count dynamic

The count to divide by (divisor).

Returns

T

Type Parameters

T

The numeric type.

CalculateMedianAverage(Dictionary<string, List<float>>, bool)

Calculates median and average statistics for categorized float values.

public static string CalculateMedianAverage(Dictionary<string, List<float>> dictionary, bool shouldThrowOnSingleElement)

Parameters

dictionary Dictionary<string, List<float>>

A dictionary mapping category names to lists of float values.

shouldThrowOnSingleElement bool

Whether to throw an exception if a category has only one element.

Returns

string

CalculateMedianAverage(List<double>, out MedianAverage<double>, bool)

Calculates median and average statistics for a list of doubles with full output.

public static string CalculateMedianAverage(List<double> list, out MedianAverage<double> medianAverage, bool shouldThrowOnSingleElement)

Parameters

list List<double>

The list of double values (zeroes will be removed).

medianAverage MedianAverage<double>

The output containing all calculated statistical values.

shouldThrowOnSingleElement bool

Whether to throw an exception if the list has only one element.

Returns

string

CalculateMedianAverage(List<double>, bool)

Calculates median and average statistics for a list of doubles.

public static string CalculateMedianAverage(List<double> list, bool shouldThrowOnSingleElement)

Parameters

list List<double>

The list of double values.

shouldThrowOnSingleElement bool

Whether to throw an exception if the list has only one element.

Returns

string

CalculateMedianAverage(List<long>, bool)

Calculates median and average statistics for a list of longs.

public static string CalculateMedianAverage(List<long> list, bool shouldThrowOnSingleElement)

Parameters

list List<long>

The list of long values.

shouldThrowOnSingleElement bool

Whether to throw an exception if the list has only one element.

Returns

string

CalculateMedianAverage(List<float>, out MedianAverage<double>, bool)

Calculates median and average statistics for a list of floats.

public static string CalculateMedianAverage(List<float> list, out MedianAverage<double> medianAverage, bool shouldThrowOnSingleElement)

Parameters

list List<float>

The list of float values.

medianAverage MedianAverage<double>

The output containing all calculated statistical values.

shouldThrowOnSingleElement bool

Whether to throw an exception if the list has only one element.

Returns

string

CalculateMedianAverageNoOut(List<float>, bool)

Calculates median and average statistics without an out parameter.

public static (string, MedianAverage<double>) CalculateMedianAverageNoOut(List<float> list, bool shouldThrowOnSingleElement)

Parameters

list List<float>

The list of float values.

shouldThrowOnSingleElement bool

Whether to throw an exception if the list has only one element.

Returns

(string, MedianAverage<double>)

CalculateMedianAverageNoOutDouble(List<double>, bool)

Calculates median and average statistics for a list of doubles without an out parameter.

public static (string, MedianAverage<double>) CalculateMedianAverageNoOutDouble(List<double> list, bool shouldThrowOnSingleElement)

Parameters

list List<double>

The list of double values.

shouldThrowOnSingleElement bool

Whether to throw an exception if the list has only one element.

Returns

(string, MedianAverage<double>)

CalculateMedianAverageT(List<double>, out MedianAverage<double>)

Calculates median and average statistics for a list of doubles.

public static string CalculateMedianAverageT(List<double> list, out MedianAverage<double> medianAverage)

Parameters

list List<double>

The list of double values (zeroes will be removed).

medianAverage MedianAverage<double>

The output containing all calculated statistical values.

Returns

string

Divide(object, object)

Casts both values to double and divides the first by the second.

public static double Divide(object dividend, object divisor)

Parameters

dividend object

The value to be divided.

divisor object

The value to divide by.

Returns

double

GenerateIntervalByte(byte, byte)

Generates an inclusive byte interval from the start value to the end value.

public static List<byte> GenerateIntervalByte(byte from, byte to)

Parameters

from byte

The start of the interval.

to byte

The end of the interval (inclusive).

Returns

List<byte>

GenerateIntervalInt(int, int)

Generates an inclusive integer interval from the start value to the end value.

public static List<int> GenerateIntervalInt(int from, int to)

Parameters

from int

The start of the interval.

to int

The end of the interval (inclusive).

Returns

List<int>

GenerateIntervalShort(short, short)

Generates an inclusive short interval from the start value to the end value.

public static List<short> GenerateIntervalShort(short from, short to)

Parameters

from short

The start of the interval.

to short

The end of the interval (inclusive).

Returns

List<short>

GetLowest(List<int>, List<int>)

Gets the lowest value from the list that is not in the excluded values.

public static int GetLowest(List<int> excludedValues, List<int> list)

Parameters

excludedValues List<int>

The list of values to exclude.

list List<int>

The list of values to search.

Returns

int

Invert(List<int>, int, int)

Creates an inverted list where missing indices are filled with a default value.

public static List<int> Invert(List<int> list, int defaultValue, int count)

Parameters

list List<int>

The source list of integer values.

defaultValue int

The value to use for indices not present in the source list.

count int

The total number of elements in the result.

Returns

List<int>

JoinAnotherTokensIfIsNumber(List<string>, int)

Joins consecutive numeric tokens starting at the specified index into a single number string.

public static string JoinAnotherTokensIfIsNumber(List<string> list, int startIndex)

Parameters

list List<string>

The list of string tokens.

startIndex int

The index to start joining from.

Returns

string

Last2NumberByte(int)

Extracts the last 2 digits of a year as a byte. Reversion is DTHelperGeneral.FullYear.

public static byte Last2NumberByte(int year)

Parameters

year int

The full year value.

Returns

byte

MakeUpTo2NumbersToZero(byte)

Pads a byte number to 2 digits with leading zero if needed.

public static string MakeUpTo2NumbersToZero(byte number)

Parameters

number byte

The byte number to pad.

Returns

string

MakeUpTo2NumbersToZero(int)

Pads an integer number to 2 digits with leading zero if needed.

public static string MakeUpTo2NumbersToZero(int number)

Parameters

number int

The integer number to pad.

Returns

string

MakeUpTo3NumbersToZero(int)

Pads an integer number to 3 digits with leading zeroes if needed.

public static string MakeUpTo3NumbersToZero(int number)

Parameters

number int

The number to pad.

Returns

string

Max(List<int>)

Finds the maximum value in a list of integers.

public static int Max(List<int> list)

Parameters

list List<int>

The list of integers.

Returns

int

MaxForLength(int)

Returns the maximum integer value that has the specified digit length.

public static int MaxForLength(int length = 4)

Parameters

length int

The number of digits.

Returns

int

Median2<T>(IList<T>)

Computes the median value using sorting. The list is not mutated.

public static double Median2<T>(IList<T> list)

Parameters

list IList<T>

The list to compute the median for.

Returns

double

Type Parameters

T

The element type.

Median<T>(IList<T>)

Computes the median value of a list. The list may be mutated during computation.

public static T Median<T>(this IList<T> list) where T : IComparable<T>

Parameters

list IList<T>

The list to compute the median for.

Returns

T

Type Parameters

T

The element type.

Median<T>(IList<T>, Func<T, double>)

Computes the median value of a sequence using a value selector function.

public static double Median<T>(this IList<T> list, Func<T, double> getValue)

Parameters

list IList<T>

The list to compute the median for.

getValue Func<T, double>

The function to extract a double value from each element.

Returns

double

Type Parameters

T

The element type.

Min(List<int>)

Finds the minimum value in a list of integers.

public static int Min(List<int> list)

Parameters

list List<int>

The list of integers.

Returns

int

MinForLength(int)

Returns the minimum integer value that has the specified digit length.

public static int MinForLength(int length = 4)

Parameters

length int

The number of digits.

Returns

int

NumberIntUntilWontReachOtherChar(string)

Extracts leading digits from a string until a non-digit character is encountered.

public static (int, string) NumberIntUntilWontReachOtherChar(string text)

Parameters

text string

The input text.

Returns

(int, string)

RemoveEndingZeroPadding(List<byte>)

Removes trailing zero bytes from the end of a byte list.

public static void RemoveEndingZeroPadding(List<byte> list)

Parameters

list List<byte>

The list of bytes to trim.

ReturnTheNearestSmallIntegerNumber(double)

Returns the nearest integer value for a double (rounds to nearest).

public static double ReturnTheNearestSmallIntegerNumber(double value)

Parameters

value double

The double value to convert.

Returns

double

Round0(float)

Rounds a float value to zero decimal places and returns as string.

public static string Round0(float value)

Parameters

value float

The float value to round.

Returns

string

RoundAndReturnInInputType(float, int)

Rounds a float value to the specified number of decimal places and returns the result as float.

public static float RoundAndReturnInInputType(float value, int decimalPlaces)

Parameters

value float

The float value to round.

decimalPlaces int

The number of decimal places.

Returns

float

Sort<T>(params T[])

Sorts the provided values and returns them as a sorted list.

public static List<T> Sort<T>(params T[] values)

Parameters

values T[]

The values to sort.

Returns

List<T>

Type Parameters

T

The type of the values.

Sum(List<string>)

Sums all values in a list of string-represented numbers.

public static double Sum(List<string> list)

Parameters

list List<string>

The list of string values to sum.

Returns

double

Sum<T>(List<T>)

Sums all values in a generic list using dynamic dispatch.

public static T Sum<T>(List<T> list)

Parameters

list List<T>

The list of values to sum.

Returns

T

Type Parameters

T

The numeric type.