December 2018
Beginner to intermediate
668 pages
15h 30m
English
Add a new console application project named WorkingWithLists.
At the top of the file, import the following namespaces:
using System; using System.Collections.Generic; using static System.Console;
In the Main method, type the following code that illustrates some of the common ways of working with lists:
var cities = new List<string>(); cities.Add("London"); cities.Add("Paris"); cities.Add("Milan"); WriteLine("Initial list"); foreach (string city in cities) { WriteLine($" {city}"); } WriteLine($"The first city is {cities[0]}."); WriteLine($"The last city is {cities[cities.Count - 1]}."); cities.Insert(0, "Sydney"); WriteLine("After inserting Sydney at index 0"); foreach (string city in cities) { WriteLine($" {city}"); } ...Read now
Unlock full access