I have a hard time getting the value of an item of a class. I'm writing a method to reading CSV file. I binding the data which I need into a class. My class looks as follows:
public class DatafromCSV
{
public string ImageId { get; set; }
public List<string> ImageBbox { get; set; }
public string Classname { get; set; }
}
This is my method to read the CSV file.
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;
}
I initialize my method as follows:
var infoCSV = ReadfromCSV(path);
After initializing the function I can access the ImageId and Classname values:
Console.WriteLine(infoCSV.ImageId);
However when I try to access the ImageBbox I getting following:
Console.WriteLine(infoCSV.ImageBbox);
System.Collections.Generic.List`1[System.String]
I expecting to get:
[2012,1367,2284,1473]
Is there a problem with how I calling it or in general in my approach? I have tried what I can but without any success. How can I get what I need?