. Create a List / generic collection of 5 capital city names in Africa.
Display all the capital cities.
Insert Ghana capital city to element 3.
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
List<string> citys = new List<string>() { "Kinshasa", "Lagos", "Cairo", "Giza", "Dar es Salaam" };
string capital = "Accra";
DisplayCities(citys);
citys.Insert(2, capital);
DisplayCities(citys);
}
static void DisplayCities(List<string> citys)
{
if (citys != null)
for (int i = 0; i < citys.Count; i++)
Console.WriteLine(citys[i]);
}
}
Comments
Leave a comment