Question
c# WINDOWS FORM APP .NET 6.0 Hi may someone pleae explain why i am receiving an array out of bounds error when trying to read
c# WINDOWS FORM APP .NET 6.0
Hi may someone pleae explain why i am receiving an array out of bounds error when trying to read in a text file into a string []?
HERE IS MY CODE:
private void Form1_Load(object sender, EventArgs e) { using (StreamReader fileIn = new StreamReader("Store-items.txt")) {
String? inputLine = fileIn.ReadLine();
while (inputLine != null) { String[] inputArray = inputLine.Split(','); String category = inputArray[0]; String item = inputArray[1]; ********* String Item IS WHAT CAUSES ERROR ** double price = double.Parse(inputArray[2]);
shoppingList.Add(newGroceriy(item,category,price));
} } }
EXAMPLE TEXT FILE:
dairy milk 2.99
dairy yogurt 1.99
candy bubblegum .75
snacks chips 1.50
the text file is composed of three categories , Two strings and one double.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started