ArrayList alist = new ArrayList();//集合對像 長度可以改變,類型不限//添加單個元素可以Add()alist.Add("在在的");alist.Add(35);alist.Add(3.14);alist.Add('c');alist.Add(5000m);//如果用Add()添加數組或集合最好用 alist.AddRange()alist.AddRange(new int[] { 3, 43, 56, 7, 98, 7, 6, 5 });alist.AddRange(alist);// alist.Add(new int[] { 3, 43, 56, 7, 98, 7, 6, 5 });//會直接打印syste.int//if (alist[i] is int[])//{// for (int j = 0; j < ((int[])alist[i]).Length; j++)// {// Console.WriteLine(((int[])alist[i])[j]);// }//}//刪除所有元素 alist.Clear();//刪除單個元素(寫誰刪誰) alist.Remove(5000m);//跟據下標刪除元素alist.RemoveAt(0);//跟據下標移除一定范圍的元素從1開始,刪除3個//升序排列 alist.Sort();//反轉 alist.Reverse();//在指定位置插入元素alist.Insert(1, 5000);//在指定位置插入集合alist.InsertRange(0,new int[]{ 3, 4, 54, 4, 23, 423, 465 });// bool b = alist.Contains(1);Console.WriteLine(b);alist.RemoveRange(1, 3);// object obj=new boject() jalist.Add(obj)for (int i = 0; i < alist.Count; i++){Console.WriteLine(alist[i]);}Console.ReadKey();
?