CodeToLive

Arrays and Collections

Arrays and collections are used to store multiple values in a single variable. C# supports arrays, lists, dictionaries, and more.

Arrays


int[] numbers = { 1, 2, 3, 4, 5 };
Console.WriteLine(numbers[0]); // Output: 1
      

Lists


List<string> names = new List<string> { "Alice", "Bob", "Charlie" };
names.Add("David");
Console.WriteLine(names[2]); // Output: Charlie
      

Dictionaries


Dictionary<string, int> ages = new Dictionary<string, int>();
ages["Alice"] = 25;
ages["Bob"] = 30;
Console.WriteLine(ages["Alice"]); // Output: 25
      
Next: Methods and Functions