Blog from Saravanan Arumugam

Let us talk about Technologies

Tag Archives: File

Read a CSV file with Linq

I just wanted to post a small code snippet, for future reference, that reads a CSV file into List of string arrays.

rawFile = (from line in File.ReadAllLines(fileName).AsParallel()
            select line.Split(',')).ToList();

File.ReadAllLines() reads all the lines from the csv into array of comma separated strings. Each line is split based on the comma into an array of strings. AsParallel() attempts to process the whole operation with multiple parallel threads.