hello, below i done a coding on visual studios but theres an error that keeps showing which is underlined and bold below, can you fix this?
class Program
{
static void Main(string[] args)
{
List
nameList = new
List
();
int choice;
do
{
DisplayMenu();
choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
{ // if user enters option 1
Console.WriteLine("\nShow Names:\n-----------");
DisplayAllNames(nameList);
break;
}
case 2:
{ // if user enters option 2
Console.WriteLine("\nAdd Name:\n---------");
AddName(nameList);
break;
}
case 3:
{ // if user enters option 3
Console.WriteLine("\nChange Name:\n------------");
ChangeName(nameList);
break;
}
case 4:
{ // if user enters option 4
Console.WriteLine("\nRemove Name:\n------------");
RemoveName(nameList);
break;
}
case 5:
{ // if user enters option 5
Console.WriteLine("\nGoodbye!\n");
break;
}
default: // if user enters any other option
Console.WriteLine("\nInvalid choice!\n");
break;
}
} while (choice != 5);
}
public static void DisplayMenu()
{
Console.Write("Choose from the following options:\n(1) Show Names\n(2) Add Name\n(3) Change Name\n(4) Remove Name\n(5) Exit\nYour selection: ");
}
public static void DisplayAllNames(
List
names)
{
if (names.Count == 0)
{
Console.WriteLine("List is empty!\n");
return;
}
Console.WriteLine("There are {0} names in the list:", names.Count);
for (int i = 0; i < names.count;="">
{
Console.WriteLine(names[i]);
}
Console.WriteLine();
}
public static int indexOf(
List
names, String name)
{
int index = -1;
for (int i = 0; i < names.count;="">
{
if (names[i].ToLower() == name.ToLower())
{
index = i;
break;
}
}
return index; // return the index
}
public static void AddName(
List
names)
{
Console.Write("Enter the name to add: ");
String userName = Console.ReadLine().Trim();
if (indexOf(names, userName) != -1)
{
Console.WriteLine("{0} is already in the list!\n", userName);
return;
}
names.Add(userName);
Console.WriteLine("{0} is added to the list.\n", userName); // display a confirmation message
}
public static void ChangeName (
List
names)
{
Console.Write("Enter an old name: ");
String userName = Console.ReadLine().Trim();
int indexOfName = indexOf(names, userName);
if (indexOfName == -1)
{
Console.WriteLine("{0} is not present in the list!\n", userName);
return;
}
Console.Write("Enter a new name to update: ");
String newUserName = Console.ReadLine().Trim();
names[indexOfName] = newUserName;
Console.WriteLine("The name is successfully updated to: {0}.\n", newUserName);
}
public static void RemoveName (
List
names)
{
Console.Write("Enter a name to remove: ");
String userName = Console.ReadLine().Trim();
int indexOfName = indexOf(names, userName);
if (indexOfName == -1)
{
Console.WriteLine("{0} is not present in the list!\n", userName); // display a message that the name is not present in the list
return;
}
names.RemoveAt(indexOfName);
Console.WriteLine("{0} is successfully removed from the list.\n", userName);
}