【发布时间】:2018-09-24 01:09:14
【问题描述】:
static void Main(string[] args)
{
string[] LinesInFile = File.ReadAllLines("D:\\Book.csv");
foreach (string line in LinesInFile)
{
if (line != "")
{
string[] columns = line.Split(',');
string PatientID = columns[0];
string DateOfBirth = columns[1];
string DateFirstSeen = columns[2];
string DateOfDiagnosis = columns[3];
string TreatmentStartDate = columns[4];
string TreatmentEndDate = columns[5];
string CancerType = columns[6];
string TreatmentType = columns[7];
Console.WriteLine(PatientID[0]);
}
}
}
这是 csv 文件中的一些数据,
1,30/07/1966,06/01/2017,21/01/2017,01/02/2017,01/06/2018,4,3
2,25/09/1970,02/01/2017,27/01/2017,04/02/2017,06/05/2018,5,1
3,23/08/1964,11/01/2017,19/01/2017,04/02/2017,31/03/2018,5,1
所以基本上当我打印“PatientID”时,它会从 1 到 3 全部打印我想要的,所以我可以单独打印每个,所以如果我只想打印第一行,我可以。我正在考虑使用一个列表来保存每个“患者”信息,但即便如此,如果我需要比较信息,我将如何单独返回每个患者的信息。
【问题讨论】:
-
在解析 csv 文件时创建一个包含患者信息的类,将每个行条目保存为 Patient 类的一个实例,然后将该实例添加到患者变量列表中,您可以使用该变量来检索每个患者的个人信息您的需求