typestar

Lists in C#

The resizable workhorse collection.

var todo = new List<string> { "write", "compile", "ship" };
todo.Add("celebrate");
todo.Insert(0, "plan");
todo.Remove("compile");

Console.WriteLine($"{todo.Count} items");
Console.WriteLine(todo.Contains("ship"));
Console.WriteLine(todo.IndexOf("ship"));
Console.WriteLine(string.Join(" -> ", todo));

How it works

  1. Add, Insert and Remove grow and shrink the list in place.
  2. Contains and IndexOf search by value.
  3. string.Join prints the whole result in one call.

Keywords and builtins used here

The run, in numbers

Lines
9
Characters to type
302
Tokens
84
Three-star pace
100 tpm

At the three-star pace of 100 tokens a minute, this run takes about 50 seconds.

Type this snippet

Step 2 of 4 in Collections, step 12 of 29 in Language basics.

← Previous Next →

Lists in other languages