using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _01ArrayList { class Program { static void Main(string[] args) { ArrayList list = new ArrayList(); list.Add(123); list.Add(‘男‘); list.Add("中国人民解放军!!!"); list.Add(3.1415926); list.Add( new char[]{‘a‘,‘b‘,‘c‘}); list.AddRange(new int[]{ 1,2,3,4,5,6,7,8,9}); //list.Clear(); //清空 //list.Remove(123); //移出--内容 //list.RemoveAt(2); //移出--索引 //list.RemoveRange(0, 5); //移出指定范围 //list.Reverse(); //反转 //list.Sort(); //排序 for (int i = 0; i < list.Count; i++) { if(list[i] is char[]) { for (int j = 0; j < ((char[])list[i]).Length; j++) { Console.WriteLine(((char[])(list[i]))[j].ToString()); } } else if(list[i] is int[]) { for (int k = 0; k < ((int[])list[i]).Length; k++) { Console.WriteLine(((int[])list[i])[k].ToString()); } }else Console.WriteLine(list[i]); } //判断内容是否存在 if (list.Contains(‘男‘)) { Console.WriteLine("This is already!"); } else { list.Add(‘男‘); } //输出arrayList的长度和内存开空间; Console.WriteLine(list.Capacity.ToString() +"---"+ list.Count.ToString()); Console.ReadKey(); } } }