What is an Array?
π‘ Concept Name
Array β A classic, fixed-size collection of elements of the same type, stored in back-to-back memory locations for fast access by index.
π Quick Intro
An array lets you store a list of values (like numbers or names) in a single variable, where each value has its own spot (called an index). Indexing always starts at zero, not one.
π§ Analogy / Short Story
Imagine an apartment block with a row of mailboxes. Every mailbox has a number starting from 0, and you can quickly check what's inside any mailbox just by knowing its number. Arrays work exactly like this β direct, no-nonsense access.
π§ Technical Explanation
- ποΈ Arrays in C# are zero-indexed, so
array[0]
gives you the first element. - π They are fixed in size β you decide the length up front and canβt resize it later (unless you create a new array).
- π§ Every element must be the same type (e.g., all
int
, allstring
). - β‘ You can access or modify any value instantly by its index.
- π In .NET, arrays are objects and are stored on the managed heap (not the stack).
π― Purpose & Use Case
- β Store a list of scores, names, or objects when you know exactly how many you need.
- β Use for 2D data like a game board or matrix.
- β Great for repetitive calculations, searching, or sorting where quick access matters.
π» Real Code Example
// Declaring and using an array
int[] scores = new int[5] { 90, 85, 88, 76, 95 };
// Accessing first value
Console.WriteLine(scores[0]); // Output: 90
// Changing the second value
scores[1] = 100; // Now scores[1] is 100
// Printing all values
foreach (int score in scores)
{
Console.WriteLine(score);
}

β Interview Q&A
Q1: What is an array?
A: A collection of elements stored in contiguous memory with a fixed size.
Q2: Can you resize an array?
A: No, arrays have a fixed size after creation.
Q3: What is the index of the first element?
A: 0
Q4: Are arrays type-safe?
A: Yes, all elements must be of the declared type.
Q5: Are arrays reference types?
A: Yes, arrays are objects in .NET.
π MCQs
Q1. What is the index of the first element in an array?
- 1
- 0
- -1
- Depends
Q2. Can arrays be resized after declaration?
- Yes
- No
- Only in C++
- Only using ref keyword
Q3. What type of elements can an array hold?
- Only one type
- Mixed types
- Any object
- Primitive types only
Q4. Where are arrays stored in memory?
- Stack
- Managed heap
- Static memory
- Global space
Q5. How is an element in an array accessed?
- By value
- By reference
- By index
- By name
π‘ Bonus Insight
Arrays are perfect when you know the number of items wonβt change. If you want something that grows and shrinks as needed, check out List<T>
β itβs like an arrayβs flexible cousin, though a tiny bit slower for raw access.
π PDF Download
Need a handy summary for your notes? Download this topic as a PDF!