I am trying to store a user input in a list. The user can enter numbers separated by a comma and then I need to perform some action based on the input that's why i am using IF later on and adding the input in a list. However if i try this then i cannot convert []string to int .
I tried to use inputs.Add(Convert.ToInt32(separatedInput)); but i get that i am Unable to cast object of type 'System.String[]' to type 'System.IConvertible'.'
List<int> userDecision = new List<int>();
Console.WriteLine("enter number separated by comma ");
var userInputs = Console.ReadLine();
var separatedInput = userInputs.Split(',');
var inputs = new List<int>();
inputs.Add(separatedInput);
if (input == 1)
{
userDecision.Add(1);
}
if (input == 2)
{
userDecision.Add(2);
}
if (input == 3)
{
userDecision.Add(3);
}
if (input == 4)
{
userDecision.Add(4);
}
if (input == -1)
{
userDecision.Add(-1);
}