Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions