• Collections are classes or structures that are designed to store and manage groups of related objects
  • provide a way to organize, manipulate, and work with multiple items of data as a single unit
  • used for various programming tasks, simple data storage or complex data processing and manipulation

Arrays

int[] numbers = new int[] { 1, 2, 3, 4, 5 };

Lists (can grow or shrink in size as needed)

List<string> names = new List<string>();
names.Add("Alice");
names.Add("Bob");
names.Add("Charlie");

Dictionaries (key-value pairs)

Dictionary<string, int> ages = new Dictionary<string, int>();
ages["Alice"] = 25;
ages["Bob"] = 30;
ages["Charlie"] = 28;

Sets (unique elements without duplicates)

HashSet<int> uniqueNumbers = new HashSet<int>();
uniqueNumbers.Add(5);
uniqueNumbers.Add(10);
uniqueNumbers.Add(5); // This won't be added since 5 is already in the set

Queues (First-In-First-Out (FIFO))

Queue<string> queue = new Queue<string>();
queue.Enqueue("First");
queue.Enqueue("Second");
string firstElement = queue.Dequeue(); // Retrieves "First"

Stacks (Last-In-First-Out (LIFO))

Stack<int> stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
int topElement = stack.Pop(); // Retrieves 2

By davs