Hi,
I am trying to combile multiple csv files to one, getting error as - in code
'IEnumerable<string[]>' does not contain a definition for 'ForEach' and no extension method 'ForEach' accepting a first argument of type 'IEnumerable<string[]>' could be found (are you missing a using directive or an assembly reference?)
CODE -
- public static void CombineMisMatchedCsvFiles(string[] filePaths, string destinationFile, char splitter = ',')
- {
-
- HashSet<string> combinedheaders = new HashSet<string>();
- int i;
-
- for (i = 0; i < filePaths.Length; i++)
- {
- string file = filePaths[i];
- combinedheaders.UnionWith(File.ReadLines(file).First().Split(splitter));
- }
- var hdict = combinedheaders.ToDictionary(y => y, y => new List<object>());
-
- string[] combinedHeadersArray = combinedheaders.ToArray();
- for (i = 0; i < filePaths.Length; i++)
- {
- var fileheaders = File.ReadLines(filePaths[i]).First().Split(splitter);
- var notfileheaders = combinedheaders.Except(fileheaders);
-
- File.ReadLines(filePaths[i]).Skip(1).Select(line => line.Split(splitter)).ForEach(spline =>
- {
- for (int j = 0; j < fileheaders.Length; j++)
- {
- hdict[fileheaders[j]].Add(spline[j]);
- }
- foreach (string header in notfileheaders)
- {
- hdict[header].Add(null);
- }
-
- });
- }