我在准确地确定如何访问和遍历类的List <>以及在类本身内输出值时遇到了麻烦。本质上,我想做的是:
Console.WriteLine(Football.team, Football.year, etc)
以获得我从.csv
文件中导入的一长串团队。
因为我是C#编程的新手,所以请放轻松。
public static void Main(string[] args)
{ // Bring in values from .csv file
List<Football> values = File.ReadAllLines("/Users/wheelK/Documents/football.csv")
.Skip(1)
.Select(v => Football.FromCsv(v))
.ToList();
}
public class Football
{
public string team;
public int year;
public int wins;
public int losses;
public int ties;
}
答案 0 :(得分:-1)
您可以使用循环:
foreach(var football in values)
{
Console.WriteLine(football.team);
}