我正在尝试使用streamreader将csvfile作为字符串读取。我一直得到参数1无法从'string'转换为System.IO.Stream。 StreamReader正在初始化StreamReader(流stream)而不是StreamReader(string)。任何帮助将不胜感激。
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;
}
}
}