【发布时间】:2020-05-26 11:12:26
【问题描述】:
我很难获得某个类别的物品的价值。 我正在编写一种读取 CSV 文件的方法。我将我需要的数据绑定到一个类中。我的班级如下所示:
public class DatafromCSV
{
public string ImageId { get; set; }
public List<string> ImageBbox { get; set; }
public string Classname { get; set; }
}
这是我读取 CSV 文件的方法。
public static DatafromCSV ReadfromCSV (string path)
{
List<string> csvLines = new List<string>();
csvLines = File.ReadAllLines(path).ToList();
csvLines = csvLines.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
DatafromCSV currentRecord = new DatafromCSV();
foreach (string line in csvLines)
{
string[] items = line.Split(',', '.');
currentRecord.ImageId = items[0];
currentRecord.ImageBbox = new List<string>() { items[2], items[3], items[4], items[5] };
currentRecord.Classname = items[6];
}
return currentRecord;
}
我按如下方式初始化我的方法:
var infoCSV = ReadfromCSV(path);
初始化函数后,我可以访问 ImageId 和 Classname 值:
Console.WriteLine(infoCSV.ImageId);
但是,当我尝试访问 ImageBbox 时,我得到以下信息:
Console.WriteLine(infoCSV.ImageBbox);
System.Collections.Generic.List`1[System.String]
我希望得到:
[2012,1367,2284,1473]
我如何称呼它或我的方法有问题吗?我已经尽我所能,但没有任何成功。我怎样才能得到我需要的东西?
【问题讨论】: