@Playstation Gamer , Welcome to Microsoft Q&A, I would recommend that you use dictionary to store the menu options and use list to save the choose options.
Here is a code example you could refer to.
static void Main(string[] args)
{
string[] AddionalExtras = new[] { "1 - Alloys", "2 - Privacy Glass", "3 - Spare Wheel", "4 - Parking Pack", "5 - SYNC 3 with Navigation", "6 - Winter Pack", "7 - Floor mats", "8 - Boot liner", "9 - Dashboard camera", "10 - Pet travel mat" }; // Any additional extras will be displayed in the array
Console.WriteLine(String.Join(Environment.NewLine, AddionalExtras)); // All of the extras are displayed from the array, line by line
List<string> list = new List<string>();
Dictionary<int,string> dic=new Dictionary<int, string>();
foreach (string item in AddionalExtras)
{
int n =Convert.ToInt32(item.Split('-')[0].Trim());
string m = item.Split('-')[1].Trim();
dic.Add(n, m);
}
while (true)
{
Console.WriteLine("Please select any of the extras that you would like to purchase!");
int ExtraSelection = Convert.ToInt32(Console.ReadLine());
if (dic.ContainsKey(ExtraSelection))
{
list.Add(dic[ExtraSelection]);
}
else
{
Console.WriteLine("Please input the correct number");
}
ConsoleKeyInfo c = Console.ReadKey();
if (c.Key == ConsoleKey.Spacebar)
{
break;
}
}
Console.WriteLine("The next is your purchase list");
foreach (var item in list)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
Note: If you want to end the choose, Please click O in the console otherwise click enter to continue to purchase something.
Result:
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.