Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将列表中的某些变量写入控制台C_C#_List_Console.writeline - Fatal编程技术网

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);
}