Console.WriteLine and generic List

后端 未结 9 1210
长发绾君心
长发绾君心 2020-11-29 01:53

I frequently find myself writing code like this:

List list = new List { 1, 3, 5 };
foreach (int i in list) {
    Console.Write(\"{0}\\t         


        
9条回答
  •  温柔的废话
    2020-11-29 02:25

    Do this:

    list.ForEach(i => Console.Write("{0}\t", i));
    

    EDIT: To others that have responded - he wants them all on the same line, with tabs between them. :)

提交回复
热议问题