使用BCL中的线性表

mac2026-02-01  2

using System; using System.Collections.Generic; namespace _001_线性表 { class Program { static void Main(string[] args) { //使用BCL中的List线性表 List<int> intList = new List<int>(); intList.Add(0);//0 intList.Add(11);//1 intList.Add(22); intList.Add(33); intList.Add(55); Console.WriteLine(intList[1]);//查找索引号为1的list内容 Console.WriteLine(intList.Count); //获取list<>的长度 // intList.Sort(); intList.Remove(11);//根据索引内容去除某个数据 intList.RemoveAt(0);//根据索引进行移除 Console.WriteLine("当前表长 :{0}",intList.Count); //获取list<>的长度 if (intList.Contains(33))//判断表中是否存在33 { Console.WriteLine("表中有33"); } Console.WriteLine("33的当前索引号:{0} ",intList.IndexOf(33)); //因为前面两位被删,所以33的索引递补到1 intList.Clear(); //清空表内的全部元素 Console.WriteLine(intList.Count); intList.Insert(0,6); //Insert(插入的索引位置,内容); Console.WriteLine("插入后索引号0的内容:{0}",intList[0]); List<int> int2List = new List<int>() { 1, 9, 2, 6, 7 }; //int2List.Sort(); } } }

最新回复(0)