[Solved] Unable to read from a CSV using List


Your example will print something like “System.Collections.Generic.List’1[System.String]” This is because the Console.WriteLine() is expecting a string (which it may be receive using the object’s ToString() method) yet you pass it a List<> object whose ToString() method returns “System.Collections.Generic.List’1[System.String]”.

Instead you need to retrieve each string from the list with a foreach loop and then print each string as you retrieve it.

For Example:

var lst = new List<string>();

lst.Add("test1");
lst.Add("test2");
lst.Add("test3");           

foreach (var item in lst)
{
    Console.WriteLine(item); // item, not list
}
Console.Read();

2

solved Unable to read from a CSV using List