Blog from Saravanan Arumugam

Let us talk about Technologies

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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: