Reading a CSV file
Now, we want to read from csv (comma separated value) file. Download the file from https://drive.google.com/open?id=0B6PPMb8KxlnQckZzM25XZnVhTGc
Then, add it to your Solution Explorer in Visual Studio. Don't forget to choose "Copy if Newer".
Create a new function to read from file, we named it ReadFile(). ReadFile
takes file as an input.
public static string ReadFile(string fileName)
{
using (var reader = new StreamReader(fileName))
{
return reader.ReadToEnd();
}
}
Get back to our Main class. Now, we could call the function.
var fileContents = ReadFile(fileName);
Console.WriteLine(fileContents);