Dogan Kirnaz
  • Welcome
  • Setup
    • Quickstart
  • Basics
    • Agent Extensions
    • Audio Extensions
    • Camera Extensions
    • Collision Extensions
    • Coroutine Extensions
    • Encryption Extensions
    • Format Extensions
    • Game Extensions
    • Json Extensions
    • List Extensions
    • Loop Extensions
    • Material Extensions
    • Math Extensions
    • GameObject Extensions
    • Physics Extensions
    • Object Pool Extensions
    • Scene Extensions
    • PlayerPrefs Extensions
  • Support
    • Support
Powered by GitBook
On this page
  1. Basics

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.

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

numbers.SwapList(0, 2);

Reverse List

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

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

numbers.ReverseList();

Pop Item

This removes and returns the specified item if it exists.

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

int popped = numbers.PopItem(1);

Pop Index

This removes and returns the item at the specified index.

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

int popped = numbers.PopIndex(0);

Get Random

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

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

int random = numbers.GetRandom();

Pop Random

This retrieves and removes a random item from the list.

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

int random = numbers.PopRandom();

Is Null Or Empty

This checks if the list is null or empty.

List<int> numbers = new List<int>();

bool isEmpty = numbers.IsNullOrEmpty();

Sort By

This sorts the list using a key selector.

List<string> names = new List<string> { "Alice", "Bob", "Charlie" };

names.SortBy(name => name.Length);

Max By

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

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

int maxNumber = numbers.MaxBy(n => n);

Min By

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

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

int minNumber = numbers.MinBy(n => n);

Add Dictionary

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

Dictionary<string, int> scores = new Dictionary<string, int>();

scores.AddDictionary("Alice", 100);

Update Dictionary

This updates the value for a key if it exists.

Dictionary<string, int> scores = new Dictionary<string, int>();

scores.UpdateDictionary("Alice", 200);

Get Dictionary

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

Dictionary<string, int> scores = new Dictionary<string, int>();

int score = scores.GetDictionary("Alice", 0);

Remove Dictionary

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

Dictionary<string, int> scores = new Dictionary<string, int>();

scores.RemoveDictionary("Alice");

Merge Dictionary

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

Dictionary<string, int> scores = new Dictionary<string, int> { { "Alice", 100 } };
Dictionary<string, int> newScores = new Dictionary<string, int> { { "Bob", 80 }, { "Alice", 200 } };

scores.MergeDictionary(newScores);
PreviousJson ExtensionsNextLoop Extensions

Last updated 23 days ago