Skip to content

IListEx

Inherits object

Public Static Functions

void

CompactNotNullElements(this IList arr)

Compacts the list by replacing null elements with the next non-null element to the right. This operation iterates once and sets each null element to the value of its immediate successor. If multiple consecutive elements are null, each will be replaced with the element immediately following it, propagating values leftward. The last element in the list is not modified.

void

Add(this IList<(K, Action)> list, K value, Delegate action)

Adds a tuple of (TValue, Action) to the list using a provided delegate.

void

Add(this IList<(TValue, Action)> list, TValue value, Delegate action)

void

Shuffle(this IList list)

Randomly shuffles the elements of the list in-place using the Fisher–Yates algorithm.

TValue

TakeRandom(this IList list)

Returns a random element from the list. A randomly chosen element from list.

TValue[]

WithoutNullElements(this IList arr)

Creates a new array containing only the non-null elements from the source list. An array of TValue with all null elements removed.

string

ToHexString(this IList bytes)

Converts a list of bytes into its uppercase hexadecimal string representation without separators. A string containing the hex representation of the bytes. The output is two hex characters per byte, using uppercase A-F, and contains no delimiters.

void

Reverse(this IList bytes)

Reverses the order of bytes in the list in-place.

void

UnionWith(this IList list, IEnumerable other)

Adds elements from other to list that are not already present, functioning as a union operation while preserving the original list. For small lists, containment checks are performed directly. For larger lists with many duplicates, a HashSet{T} is created after a threshold of observed duplicates to improve performance.

Private Attributes

Random

RNG

A shared random number generator used by methods requiring randomness.