C#C
C#2y ago
js

invalid index error which i dont understand

string temp = selectionItems[selection-1].ToString();
string name = temp.Substring(0, temp.IndexOf(","));
string toppings = temp.Substring(temp.IndexOf(","), temp.IndexOf("£"));
string[] toppingsArray = toppings.Split(", ");
List<string> toppingsList = toppingsArray.ToList();
toppingsList.RemoveAt(0);
Console.WriteLine(selectionItems[selection-1]);
Console.WriteLine(temp.IndexOf("£"));
Console.WriteLine(temp.Length);
string stringPrice = temp.Substring(temp.IndexOf("£"), temp.Length-1);
Console.WriteLine(stringPrice);
string pricetemp = temp.Substring(temp.IndexOf("£", temp.Length-1));
pricetemp = pricetemp.Remove(pricetemp.IndexOf("£"));
pricetemp = pricetemp.Remove(pricetemp.IndexOf("."));
int intPrice = int.Parse(pricetemp);
Pizza pizza = new Pizza(name, toppingsList, intPrice, stringPrice);
image.png
Was this page helpful?