I am witting a program to fetch a large number of .csv files, read them and find an product with the highest frequency. What I want to do is read the files using Parallel.ForEach loop to read the files and store the products into a ConcurrentDictionary (since its thread safe). What I want know is to find a way to count the number of times a particular product is read and store that frequency as it's key, and the value as the name of the product itself. Any help please ?
Here is my code:
string[] files = File.ReadAllLines(@"C:\Users\Samuel Hendrix\Desktop\StoreData\StoreData\" + selectedStore + @"_" + selectedWeek + "_" + selectedYear + @".csv");
decimal cost;
//Splitting the content of the files into arrays, which are then stored into variable to be added to lists
Parallel.ForEach (files, file =>
{
string[] orderSplit = file.Split(',');
string items = orderSplit[0];
Products.TryAdd(items, items.Count() );
});