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
Add,InsertandRemovegrow and shrink the list in place.ContainsandIndexOfsearch by value.string.Joinprints the whole result in one call.
Keywords and builtins used here
newstringvar
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.
Step 2 of 4 in Collections, step 12 of 29 in Language basics.