Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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
List 用c语言打印动态列表项#_List_C# 4.0 - Fatal编程技术网

List 用c语言打印动态列表项#

List 用c语言打印动态列表项#,list,c#-4.0,List,C# 4.0,我有下面这样的代码 主要问题是我想在控制台上打印每个列表项 List<Branches> branchesList = new List<Branches>() { new Branches(){branchId = 1, branchName="Cardeology"}, new Branches(){branchId = 2, branchName="Urology"},

我有下面这样的代码

主要问题是我想在控制台上打印每个列表项

List<Branches> branchesList = new List<Branches>()
            {
                new Branches(){branchId = 1, branchName="Cardeology"},
                new Branches(){branchId = 2, branchName="Urology"},
                new Branches(){branchId = 3, branchName="Dentistry"},

            };
List branchesList=newlist()
{
新分支(){branchId=1,branchName=“Cardeology”},
新分支(){branchId=2,branchName=“泌尿学”},
新分支(){branchId=3,branchName=“牙科”},
};

这就是你可以做到的

foreach(var item in branchesList){
  Console.WriteLine("Branch: " + item.branchId + ", BranchName: "+ item.branchName);
}
Console.ReadKey();
另一种方式

for(int i = 0; i < branchesList.Count(); i ++){
Console.WriteLine("Branch: " + branchesList[i].branchId + ", BranchName: "+ branchesList[i].branchName);
}
Console.ReadKey();
for(int i=0;i