static void Main(string[] args)
{
var scorelist = new List<int>();
scorelist.Add(100);
scorelist.Add(200);
scorelist.Add(300);//添加元素
foreach (var temp in scorelist)
{
Console.WriteLine(temp);
}
Console.WriteLine("------------");
scorelist.Insert(1, -1);//插入,表示在索引1的位置,插入-1
foreach (var temp in scorelist)
{
Console.WriteLine(temp);
}
Console.WriteLine("------------");
scorelist.RemoveAt(1);//移出指定位置的索引
foreach (var temp in scorelist)
{
Console.WriteLine(temp);
}
Console.ReadKey();
}
排序属性
static void Main(string[] args)
{
var scorelist = new List<int>();
scorelist.Add(100);
scorelist.Add(200);
scorelist.Add(400);
scorelist.Add(300);//添加元素
foreach (var temp in scorelist)
{
Console.WriteLine(temp);
}
Console.WriteLine("-----------");
int index= scorelist.IndexOf(200);//找到元素的索引位置,如果元素不存在,会返回-1
Console.WriteLine(index);
Console.WriteLine("-----------");
Console.WriteLine(scorelist.IndexOf(100));//会从第一个位置开始搜索,找到与位置匹配的
Console.WriteLine(scorelist.LastIndexOf(100));//会从后往前搜索
scorelist.Sort();//从小到大排序
foreach (var temp in scorelist)
{
Console.WriteLine(temp);
}
Console.ReadKey();
}