The program is meant to read in information from a .csv
file; then with the data from this file the Product
objects are to be created and then stored in a list.
My problem is that I have no idea how to transfer the data from the .csv
file that will be split up by ',' and stored in an array to the constructor objects. Any help would be greatly appreciated.
The .csv
looks like this:
Here is my code thus far:
class Product
{
public string ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Price { get; set; }
public string StockAvailable { get; set; }
public string WeeklySales { get; set; }
// Constructor
public Product(string iD, string name, string Desc, string price, string StockAva, string weeklysales)
{
ID = iD;
Name = name;
Description = Desc;
Price = price;
StockAvailable = StockAva;
WeeklySales = weeklysales;
}
}
private static void ReadProductFile()
{
string productPath = GetDataDirectory("prod");
string[] fileData = File.ReadAllLines(productPath);
string[] productDetails = new string[20];
for (int i = 0; i < fileData.Length; i++)
{
productDetails = fileData[i].Split(',');
// I have no idea what do do next!
}
}