当前位置:主页 > 软件编程 > .NET代码 >

C#控制台基础 list<>初始化的两种方法

时间:2021-08-08 08:24:40 | 栏目:.NET代码 | 点击:

代码一、

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

代码二、

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

您可能感兴趣的文章:

相关文章