I am trying to get streamreader to read a csvfile as a string. I keep getting the argument 1 cannot convert from 'string' to System.IO.Stream. The StreamReader is initializing StreamReader(stream stream) instead of StreamReader(string). Any help would be greatly appreciated.
public class CsvParser
{
public static void LoadAndParse()
{
string csvData = @"text.csv";
var fileContents = Parse(csvData);
}
public static List<StockInfo> Parse(string csvData)
{
var stocks = new List<StockInfo>();
using (StreamReader reader = new StreamReader(csvData))
{
string line = "";
while ((line = reader.ReadLine()) != null)
{
string[] cols = line.Split(',');
StockInfo s = new StockInfo();
s.Date = Convert.ToDateTime(cols[0].Trim());
s.Open = Convert.ToDecimal((cols[1]));
s.High = Convert.ToDecimal((cols[2]));
s.Close = Convert.ToDecimal((cols[3]));
stocks.Add(s);
}
return stocks;
}
}
}