using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1   //List<> 的声明与使用
{ 
    class Program
    {       
        static void Main(string[] args)
        {
            //   List<int> mylist = new List<int>();
             var mylist = new List<int>();
            //  var mylist = new List<int> { 1 ,2, 3 };
            mylist.Add(10);   //添加第一个数值
            mylist.Add(20);   //添加第二个数值
            Console.WriteLine(mylist[0]); //访问第一个数值
            Console.ReadKey();
       
        }
    }
}

我演示了三种创建List的方法,分别是直接创建,匿名创建,还有创建的时候填上初值。

相关文章:

  • 2022-12-23
  • 2021-07-22
  • 2021-11-23
  • 2021-09-07
  • 2022-03-05
  • 2021-09-18
  • 2022-01-01
  • 2021-04-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
相关资源
相似解决方案