List Extensions

Add List

This adds an item to the list only if it doesn't already exist.

List<int> numbers = new List<int> { 1, 2, 3 };

numbers.AddList(3); // This will be ignored

Remove List

This removes an item from the list only if it exists.

List<int> numbers = new List<int> { 1, 2, 3 };

numbers.RemoveList(4); // This will be ignored

Shuffle List

This randomly shuffles the items in the list.

List<int> numbers = new List<int> { 1, 2, 3 };

numbers.ShuffleList();

Swap List

This swaps two elements in the list based on their indices.

Reverse List

This swaps two elements in the list based on their indices.

Pop Item

This removes and returns the specified item if it exists.

Pop Index

This removes and returns the item at the specified index.

Get Random

This retrieves a random item from the list without removing it.

Pop Random

This retrieves and removes a random item from the list.

Is Null Or Empty

This checks if the list is null or empty.

Sort By

This sorts the list using a key selector.

Max By

This retrieves the item with the highest value based on the selector.

Min By

This retrieves the item with the lowest value based on the selector.

Add Dictionary

This adds a key-value pair if the key doesn't already exist.

Update Dictionary

This updates the value for a key if it exists.

Get Dictionary

This retrieves a value or returns a default value if the key doesn't exist.

Remove Dictionary

This removes a key-value pair if the key exists.

Merge Dictionary

This merges another dictionary into the current dictionary, overwriting existing keys.

Last updated