Skip to content
Learn Netverks

Lesson

Step 18/36 50% through track

arrays-lists

Arrays and lists

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Arrays and lists: the syntax, patterns, and safety habits you need before advancing in C#.

Teams still ship Arrays and lists in C# codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Arrays and lists in contexts like: .NET services, Unity games, and Windows-centric tooling.

Write C# with Console.WriteLine (top-level or Program), click Run on server—the dev runner uses dotnet build/run on a temp net8 project (requires .NET SDK; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

C# arrays are fixed-length: int[] scores = {88, 92, 75};. List<T> from System.Collections.Generic is resizable—the default dynamic collection, similar to ArrayList in Java.

Array and List basics

int[] nums = {10, 20, 30};
List<string> names = new List<string> { "Ada", "Grace" };
names.Add("Alan");
Console.WriteLine(names[0]);

Arrays expose Length; lists use Count. Both support foreach and index access.

When to use which

  • Array — fixed size known upfront, interop, performance-sensitive buffers
  • List<T> — grow/shrink at runtime, most application collections

Important interview questions and answers

  1. Q: Array vs List?
    A: Array fixed size; List resizable with helper methods like Add and RemoveAt.
  2. Q: Why generics?
    A: Compile-time type safety—no casting from raw collections like pre-generics Java.

Self-check

  1. Which property gives an array's length?
  2. Which method adds to a List?

Tip: Default to List<T> for resizable collections—arrays are fixed length and mainly for interop or known-size buffers.

Interview prep

Array vs List?

Arrays are fixed size with Length; List<T> is resizable with Add, RemoveAt, and Count.

Why List&lt;T&gt; over ArrayList?

Generics give compile-time type safety—no casting from raw collections like pre-generics Java.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • List vs array?
  • Capacity growth?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump