Methods of Generic and Non-Generic Collections in C#
Generic Collections
List<T>
Method Description Example
Add(T item) Adds an item to the end. [Link](4);
AddRange(IEnumerable<T> Adds a range of items. [Link](new[] { 5,
) 6 });
Insert(int index, T item) Inserts an item at a specific [Link](1, 10);
index.
Remove(T item) Removes the first [Link](2);
occurrence of an item.
RemoveAt(int index) Removes an item by index. [Link](0);
Contains(T item) Checks if an item exists. [Link](3);
Find(Predicate<T>) Finds an item matching a [Link](x => x > 2);
condition.
Sort() Sorts the list. [Link]();
Clear() Removes all items. [Link]();
Count Gets the number of items. int count = [Link];
Dictionary<TKey, TValue>
Method Description Example
Add(TKey, TValue) Adds a key-value pair. [Link](1, "One");
Remove(TKey) Removes an entry by key. [Link](1);
TryGetValue(TKey, out Tries to get a value by key. [Link](1, out
TValue) string value);
ContainsKey(TKey) Checks if a key exists. [Link](1);
ContainsValue(TValue) Checks if a value exists. [Link]("One");
Clear() Removes all entries. [Link]();
Count Gets the number of entries. int count = [Link];
Queue<T>
Method Description Example
Enqueue(T item) Adds an item to the end. [Link]("Task 1");
Dequeue() Removes and returns the [Link]();
first item.
Peek() Returns the first item [Link]();
without removing.
Contains(T item) Checks if an item exists. [Link]("Task 1");
Clear() Removes all items. [Link]();
Stack<T>
Method Description Example
Push(T item) Adds an item to the top. [Link](1);
Pop() Removes and returns the [Link]();
top item.
Peek() Returns the top item [Link]();
without removing.
Contains(T item) Checks if an item exists. [Link](1);
Clear() Removes all items. [Link]();
HashSet<T>
Method Description Example
Add(T item) Adds an item. [Link](1);
Remove(T item) Removes an item. [Link](1);
Contains(T item) Checks if an item exists. [Link](1);
UnionWith(IEnumerable<T Combines with another [Link](new[] { 3,
>) collection. 4 });
Clear() Removes all items. [Link]();
Non-Generic Collections
ArrayList
Method Description Example
Add(object item) Adds an item. [Link](1);
Remove(object item) Removes the first [Link](1);
occurrence of an item.
RemoveAt(int index) Removes an item by index. [Link](0);
Contains(object item) Checks if an item exists. [Link](1);
Clear() Removes all items. [Link]();
Sort() Sorts the list. [Link]();
Hashtable
Method Description Example
Add(object key, object Adds a key-value pair. [Link](1, "One");
value)
Remove(object key) Removes an entry by key. [Link](1);
ContainsKey(object key) Checks if a key exists. [Link](1);
ContainsValue(object value) Checks if a value exists. [Link]("One");
Clear() Removes all entries. [Link]();
Queue
Method Description Example
Enqueue(object item) Adds an item to the end. [Link](1);
Dequeue() Removes and returns the [Link]();
first item.
Peek() Returns the first item [Link]();
without removing.
Clear() Removes all items. [Link]();
Stack
Method Description Example
Push(object item) Adds an item to the top. [Link](1);
Pop() Removes and returns the [Link]();
top item.
Peek() Returns the top item [Link]();
without removing.
Clear() Removes all items. [Link]();