Answer to Question #345357 in C# for raymond

Question #345357

. Create a List / generic collection of 5 capital city names in Africa.




Display all the capital cities.




Insert Ghana capital city to element 3.





1
Expert's answer
2022-05-26T16:56:56-0400
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]);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS