【可以删除ArrayList中某个指定位置的元素吗?有哪几种方法?】
关键代码:
static void Main(string[] args)
{
ArrayList arrayList=new ArrayList(6);
arrayList.Add(666);
arrayList.Add("恒超商务");
arrayList.Add("www");
arrayList.Add("济南网站建设");
arrayList.Add("云服务器");
arrayList.Add("网站空间");
arrayList.Add("虚拟主机");
arrayList.Add("小程序");
Console.WriteLine("源数据是:");
foreach (object a in arrayList)
{
Console.Write(a+" ");
}
Console.WriteLine("使用Remove方法删除元素:");
arrayList.Remove("小程序");
foreach (object a in arrayList)
{
Console.Write(a + " ");
}
Console.WriteLine("使用RemoveAt方法删除元素:");
arrayList.RemoveAt(1);
foreach (object a in arrayList)
{
Console.Write(a + " ");
}
Console.WriteLine("使用RemoveRange方法删除元素:");
arrayList.RemoveRange(2,1);
foreach (object a in arrayList)
{
Console.Write(a + " ");
}
Console.WriteLine("使用clear方法移除所有元素:");
arrayList.Clear();
foreach (object a in arrayList)
{
Console.Write(a + " ");
}
Console.ReadKey();
}
评论