List inside list does not print elements, instead shows System.Collections.Generic.List`1[System.Object]

前端 未结 3 1879
醉酒成梦
醉酒成梦 2020-12-11 10:00

I have a list which contains three items. First element is integer, second one is also an integer and third one is another list. By using for each loop I\'m able to print th

3条回答
  •  情歌与酒
    2020-12-11 10:48

    If your first two items in mainList really are fixed then change this

    foreach(var i in mainList)
    {
       Console.WriteLine(i); // Prints items      
    }
    

    to

    Console.WriteLine(mainList.Item[0]);
    Console.WriteLine(mainList.Item[1]);
    
    foreach(var i in mainList.Item[2])
    {
       Console.WriteLine(i); // Prints items      
    }
    

    Looks pretty ugly to me, though.

提交回复
热议问题