C# 如何将列表中的某些变量写入控制台C
编辑 如果我从列表中分别写出每一个,我就能写出我需要的东西C# 如何将列表中的某些变量写入控制台C,c#,list,console.writeline,C#,List,Console.writeline,编辑 如果我从列表中分别写出每一个,我就能写出我需要的东西 public class Stylist { public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } public string Phone { get; set; } public string Rate { get; set; } }
public class Stylist
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Rate { get; set; }
}
我试过用foreach
但这只打印ACW_编程2.设计师
ACW_Programming2是项目名称作为Giorgi答案的替代,您可以覆盖设计师的ToString方法
foreach (object i in stylists)
{
Console.WriteLine(i);
}
foreach (var i in stylists)
{
Console.WriteLine(i.FirstName + " " + i.LastName);
}
那就照你做的去做
public class Stylist
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Rate { get; set; }
public override string ToString()
{
return FirstName + " " + LastName;
}
}
你对此做过任何研究吗?试过什么吗?把你已经试过的贴出来。
foreach (var i in stylists)
{
Console.WriteLine(i.FirstName + " " + i.LastName);
}
public class Stylist
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Rate { get; set; }
public override string ToString()
{
return FirstName + " " + LastName;
}
}
foreach (Stylist i in stylists)
{
Console.WriteLine(i);
}