Console.WriteLine and generic List

后端 未结 9 1204
长发绾君心
长发绾君心 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:35
    public static void WriteLine(this List<int> theList)
    {
      foreach (int i in list)
      {
        Console.Write("{0}\t", t.ToString());
      }
      Console.WriteLine();
    }
    

    Then, later...

    list.WriteLine();
    
    0 讨论(0)
  • 2020-11-29 02:38
    new List<int> { 1, 3, 5 }.ForEach(Console.WriteLine);
    
    0 讨论(0)
  • 2020-11-29 02:42
    List<int> list = new List<int> { 1, 3, 5 };
    list.ForEach(x => Console.WriteLine(x));
    

    Edit: Dammit! took too long to open visual studio to test it.

    0 讨论(0)
提交回复
热议问题