014_列表List的创建和使用。

namespace _014_列表List的创建和使用 { class Program { static void Main(string[] args) {

 //ListscoreList = new List();

//创建了一个空的列表 通过类型后面的<>来表示这个列表存储的数据的类型

 var scoreList = new List(); 

 //var scoreList = new List(){1,2,3};//创建了一个列表,里面的初始值有三个分别为 1 2 3

            //Console.WriteLine("capacity:"+scoreList.Capacity+" count:"+scoreList.Count);

            //scoreList.Add(12);//向列表中插入数据

            //Console.WriteLine("capacity:" + scoreList.Capacity + " count:" + scoreList.Count);

            //scoreList.Add(45);

            //Console.WriteLine("capacity:" + scoreList.Capacity + " count:" + scoreList.Count);

            //Console.WriteLine(scoreList[0]);//根据索引访问数据

            for (int i = 0; i < 20; i++)

            {

                Console.WriteLine("capacity:" + scoreList.Capacity + " count:" + scoreList.Count);

                scoreList.Add( 10 );

            }

            //Console.WriteLine(scoreList[2]);//索引不存在的时候,会出现异常

            Console.ReadKey();

        }

    }

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容