I try to get a file's content into an array in C#. My program is similar to a shopping list. I'm not able to store the data as a JSON file cause of some requirements.
I decided to store the data like:
3x water
2x fish
I grabbed the data using a simple StreamReader and got all the data into a string.
I tried to separate the string by \n using split and store the data into a string array.
Now I wanted to split each string again to get the quantity of the product. I tried splitting each index using a foreach and storing them in a second array. I also tried to store the data in the same array.
I want to get something like
string[] cars = {"3", "water", "2", "fish"};
or store the data in a list. Is my attempt a bad one?
Is there a way to do it much more easily?
int.Parseon the first item to get a numeric value. But you really need to include your code and if it's working then this might be off topic and codereview.stackexchange.com might be a better fit if you're asking for a review of your existing working code.Carslike :Car[] cars = new Car[] { new Car(3, "water"), new Car(2, "fish") };?