© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
13 replies
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);
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,828Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

I dont understand whats wrong?
C#CC# / help
2h ago
✅ I dont understand this error in my code
C#CC# / help
2y ago
I dont understand how this works
C#CC# / help
3y ago
❔ Hello I am new to C#, I dont understand this error:
C#CC# / help
3y ago