我对编程非常非常陌生,我目前正在尝试尽可能快地学习它,以满足我的研究要求。我正在尝试从文本文档创建一个类。我已经生成了下面的代码,但是它在我调试时返回错误,我不确定如何修复。
List<Partitions> ListofPartitions = new List<Partitions>();
System.IO.StreamReader sr = new System.IO.StreamReader("C:\\Partitions.csv")
{
string line = sr.ReadToEnd();
Partitions Pname = new Partitions(line);
Partitions Plength = new Partitions(line);
Partitions Pdepth = new Partitions(line);
Partitions Pheight = new Partitions(line);
}
}
public class Partitions
{
string parameters;
public int Pname;
public double Plength;
public double Pdepth;
public double Pheight;
public Partitions(string inputLine)
{
parameters = inputLine;
string[]split = parameters.Split(',');
Pname = Convert.ToInt16(split[0]);
Plength = Convert.ToDouble(split[1]);
Pdepth = Convert.ToDouble(split[2]);
Pheight = Convert.ToDouble(split[3]);
}
返回错误:GA.xaml.cs(39,24):错误 CS1525:无效的表达式术语“字符串”GA.xaml.cs(39,45):错误 CS1003:语法错误,“,”预期
任何帮助将非常感激。