Question: Create a new C# Console project called ColorList. Create a utility method called Print to use with the Lists built in ForEach function: private static

Create a new C# Console project called ColorList.

  • Create a utility method called Print to use with the Lists built in ForEach function:

private static void Print(string s)

{

Console.WriteLine(s);

}

  • In the Main method of the application, define a List of strings called Colors:

List Colors = new List();

  • Call the Add( ) method of the Colors list to add the following string items in this order:

White, Red, Orange, Yellow, Green, Blue, Indigo, Violet, Black

  • Print the list by passing the Print method to the lists ForEach method.
  • Use the Count( ) method of your list and save the return.
  • Write the value to the console in a string that says The Colors list has {0} items.
  • Sort the list by calling its Sort() method
  • Use a foreach loop to write all the items to the console:

foreach (string color in Colors)

{

Console.WriteLine(color);

}

  • Use indexOf() to find the index number for the string Violet

int index = colors.IndexOf("Violet");

  • Use Remove( ) to remove the item Violet using the index number.
  • Use Insert( ) to put the string Purple in the second last location.
  • Repeat the foreach loop to see the modified list.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!