Ms_ Dev

Ms_ Dev

  • NA
  • 236
  • 88.7k

LINQ Error IN ForEach

Mar 15 2018 9:33 AM
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 - 
  1. public static void CombineMisMatchedCsvFiles(string[] filePaths, string destinationFile, char splitter = ',')  
  2.         {  
  3.   
  4.             HashSet<string> combinedheaders = new HashSet<string>();  
  5.             int i;  
  6.             // aggregate headers  
  7.             for (i = 0; i < filePaths.Length; i++)  
  8.             {  
  9.                 string file = filePaths[i];  
  10.                 combinedheaders.UnionWith(File.ReadLines(file).First().Split(splitter));  
  11.             }  
  12.             var hdict = combinedheaders.ToDictionary(y => y, y => new List<object>());  
  13.   
  14.             string[] combinedHeadersArray = combinedheaders.ToArray();  
  15.             for (i = 0; i < filePaths.Length; i++)  
  16.             {  
  17.                 var fileheaders = File.ReadLines(filePaths[i]).First().Split(splitter);  
  18.                 var notfileheaders = combinedheaders.Except(fileheaders);  
  19.   
  20.                 File.ReadLines(filePaths[i]).Skip(1).Select(line => line.Split(splitter)).ForEach(spline =>  
  21.                 {  
  22.                     for (int j = 0; j < fileheaders.Length; j++)  
  23.                     {  
  24.                         hdict[fileheaders[j]].Add(spline[j]);  
  25.                     }  
  26.                     foreach (string header in notfileheaders)  
  27.                     {  
  28.                         hdict[header].Add(null);  
  29.                     }  
  30.   
  31.                 });  
  32.             }  

Answers (1)