SoFunction
Updated on 2025-03-06

C# console basics Two methods of list initialization

Code 1.

using System;
using ;
using ;
using ;
using ;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      List<int> list1 = new List<int> { 1, 2, 3, 4, 5, };
    }
  }
}

Code 2.

using System;
using ;
using ;
using ;
using ;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      List<int> list1 = new List<int>();
      (1);
      (2);
      (3);
      (4);
      (5);
    }
  }
}

The above are the two methods of initializing list<>. I hope everyone will support me in the future.