Introduction to Arrays
Learn how to store and manage multiple data items using arrays.
Introduction to Arrays is a free C# Academy lesson on CoddyKit — lesson 4 of 5. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C# Academy learning path, one of 5 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Introduction to Arrays
Welcome to the next lesson! In this lesson, you’ll learn how to work with arrays in C# to store and manage multiple values efficiently. Let’s get started!

2
What Are Arrays?
An array is a collection of elements of the same type, stored in a contiguous block of memory. Arrays allow you to group related data together and access them using an index.
Example: A list of student grades or names can be stored in an array.
Key Point: Arrays in C# are zero-indexed, meaning the first element is at index 0.
3
Declaring and Initializing Arrays
You can declare and initialize an array in a single step. Example:
Tip: Use square brackets [] to access array elements by their index.
using System;
class Program {
static void Main() {
int[] numbers = { 1, 2, 3, 4, 5 }; // Declare and initialize an array
Console.WriteLine("First number: " + numbers[0]); // Access the first element
}
}
4
Accessing Array Elements
Array elements are accessed using their index. Example:
Key Point: Ensure the index is within the bounds of the array to avoid runtime errors.
using System;
class Program {
static void Main() {
string[] names = { "Alice", "Bob", "Charlie" };
Console.WriteLine("First name: " + names[0]); // Outputs: Alice
Console.WriteLine("Second name: " + names[1]);
// Outputs: Bob
Console.WriteLine("Third name: " + names[2]); // Outputs: Charlie
}
}5
Modifying Array Elements
You can modify the value of an array element by assigning a new value to it. Example:
Tip: Use this feature to update values dynamically in your program.
using System;
class Program {
static void Main() {
int[] scores = { 10, 20, 30 };
scores[1] = 25; // Modify the second element
Console.WriteLine("Updated second score: " + scores[1]); // Outputs: 25
}
}6
Iterating Over Arrays
Use loops like for or foreach to iterate through an array. Example:
Key Point: The foreach loop is simpler for reading array values, but the for loop provides access to the index.
using System;
class Program {
static void Main() {
int[] numbers = { 10, 20, 30, 40 };
foreach (int number in numbers) {
Console.WriteLine(number); // Outputs each number
}
}
}
7
Multi-Dimensional Arrays
Multi-dimensional arrays store data in a grid-like structure. Example:
Tip: Use commas inside brackets to declare the dimensions of the array.
using System;
class Program {
static void Main() {
int[,] matrix = {
{ 1, 2, 3 },
{ 4, 5, 6 }
};
Console.WriteLine("Element at (0,1): " + matrix[0, 1]); // Outputs: 2
}
}
8
Practice Challenge
Write a program that stores 5 numbers in an array, then calculates and prints their total. Example:
using System;
class Program {
static void Main() {
int[] numbers = { 5, 10, 15, 20, 25 };
int total = 0;
foreach (int number in numbers) {
total += number; // Add each number to the total
}
Console.WriteLine("Total: " + total); // Outputs: Total: 75
}
}
9
10
Great Job!
Congratulations! You’ve learned how to declare, access, modify, and iterate through arrays in C#. In the next lesson, we’ll explore working with strings and their powerful features. Let’s keep coding!

Frequently asked questions
Is the “Introduction to Arrays” lesson free?
Yes — the full text of “Introduction to Arrays” is free to read here on the web, and the C# Academy course includes 5 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C# Academy course, upgrade to CoddyKit PRO.
What will I learn in “Introduction to Arrays”?
Learn how to store and manage multiple data items using arrays. You practise C# Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C# Academy?
No prior experience is required. C# Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 5, so you can start here or from the beginning and move at your own pace.
How long does the “Introduction to Arrays” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C# Academy lesson?
Yes. Every C# Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.