list泛型的使用 ArrayList list = new ArrayList(); ArrayList list = new ArrayList(5); //可變數組 list.Add("我"); //Add 添加 向數組中賦值索引為最末尾 list.Add("今年"); list.Add("18"); list.Add("歲了"); list.Add("18"); list.Add("歲了"); list.Add("18"); list.Add("歲了"); 知識點 list.Contains();//查詢數組中元素是否存在 list.CopyTo(); //賦值數組中的全部數據 list.RemoveAt();//根據索引把指定位置元素刪除 list.Remove(); //移除的是元素 list.Clear();//清空數組 list.Count; //數組元素的個數 舉例子 bool result = list.Contains("我"); //返回bool 查詢數組中元素是否存在 string[] list1 = new String[15]; list.CopyTo(list1); //賦值數組中的全部數據 賦值的集合的數據類型要一致 oblect[] list1 = new oblect[15]; list.CopyTo(list1); //賦值數組中的全部數據 賦值的集合的數據類型可以不一致 list.RemoveAt(6); //把第七個元素移除 list.Remove("我"); //移除的是元素 int index=list.Count; Console.WriteLine(index); Console.WriteLine(list[6]); foreach (object val in list) { Console.WriteLine(val); } Console.ReadKey(); #endregion #region 泛型集合 List<int> intList=new List<int>(); //List泛型集合 類型是一致的 intList.Add(12); intList.Add(23); intList.Add(34); int result = intList.IndexOf(34);//根據元素,查找返回該元素的索引位置,如果沒有,返回-1 可以指定索引范圍(34,0,2) //知識點 intList.Add();//查詢數組中元素是否存在 intList.CopyTo(); //賦值數組中的全部數據 intList.RemoveAt();//根據索引把指定位置元素刪除 intList.Remove(); //移除的是元素 intList.IndexOf(); //根據元素,查找返回該元素的索引位置,如果沒有,返回-1 intList.Insert(1,16);//將元素插入集合某處 //舉例子 intList[0] = 15; intList.Insert(0,16);//將元素插入集合某處 原來索引位置的元素值自動下移,整理向后移動 Console.WriteLine(intList[0]); Console.ReadKey(); #endregion #region 泛型數組練習 List<string> arrList=new List<string>(); arrList.Add("張三"); arrList.Add("年齡"); arrList.Add("身高"); arrList.Add("電話號碼"); int a = arrList.Count; string name = ""; for (int i = 0; i < arrList.Count; i++) { if(arrList[0].Equals("張三")) { arrList[0] += "今年的"; Console.WriteLine(arrList[0]); } } Console.ReadKey();
本系列教程:
C#基礎總結之八面向對象知識點總結-繼承與多態-接口-http://www.cnblogs.com/spring_wang/p/6113531.html
C#基礎總結之七面向對象知識點總結1http://www.cnblogs.com/spring_wang/p/6113526.html
C#基礎總結之六 DataTable (臨時表/數據源) 和Datatable 名片練習http://www.cnblogs.com/spring_wang/p/6113520.html
C#基礎總結之五Dictionary<string, string[]>和while循環http://www.cnblogs.com/spring_wang/p/6113514.html
C#基礎總結之四List-Hashtable-冒泡排序http://www.cnblogs.com/spring_wang/p/6113504.html
C#基礎總結之三循環控制-for-數組-乘法表-arraylisthttp://www.cnblogs.com/spring_wang/p/6113496.html
C#基礎總結之二循環控制-運算符http://www.cnblogs.com/spring_wang/p/6113484.html
C#基礎總結之一變量常量-if嵌套語句-witch結構-類型轉換http://www.cnblogs.com/spring_wang/p/6113476.html
C#基礎課程之六(臨時表)DataTable使用方法http://www.cnblogs.com/spring_wang/p/6113454.html
C#基礎課程之五集合(HashTable,Dictionary)http://www.cnblogs.com/spring_wang/p/6113404.html
C#基礎課程之四集合(ArrayList、List<泛型>)http://www.cnblogs.com/spring_wang/p/6113396.html
C#基礎課程之三循環語句http://www.cnblogs.com/spring_wang/p/6113383.html
C#基礎課程之二變量常量及流程控制http://www.cnblogs.com/spring_wang/p/6113372.html
C#基礎課程之一注釋和控制台、一些常識http://www.cnblogs.com/spring_wang/p/6113361.html
C#基礎第九天-作業答案-儲蓄賬戶(SavingAccount)和信用賬戶(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113291.html
C#基礎第九天-作業-儲蓄賬戶(SavingAccount)和信用賬戶(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113285.html
C#基礎第八天-作業答案-設計類-面向對象方式實現兩個帳戶之間轉賬http://www.cnblogs.com/spring_wang/p/6113274.html
C#基礎第八天-作業-設計類-面向對象方式實現兩個帳戶之間轉賬http://www.cnblogs.com/spring_wang/p/6113258.html
C#基礎第七天-作業答案-利用面向對象的思想去實現名片-動態添加http://www.cnblogs.com/spring_wang/p/6113232.html
C#基礎第七天-作業-利用面向對象的思想去實現名片-動態添加http://www.cnblogs.com/spring_wang/p/6113224.html
C#基礎第六天-作業-利用面向對象的思想去實現名片http://www.cnblogs.com/spring_wang/p/6113028.html
C#基礎第六天-作業答案-利用面向對象的思想去實現名片http://www.cnblogs.com/spring_wang/p/6113033.html
C#基礎第五天-作業答案-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113022.html
C#基礎第五天-作業-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113013.html
C#基礎第四天-作業答案-Hashtable-list<KeyValuePair>泛型實現名片http://www.cnblogs.com/spring_wang/p/6113005.html
C#基礎第四天-作業-Hashtable-list<KeyValuePair>泛型實現名片http://www.cnblogs.com/spring_wang/p/6113000.html
C#基礎第三天-作業答案-集合-冒泡排序-模擬名片http://www.cnblogs.com/spring_wang/p/6112888.html
C#基礎第三天-作業-集合-冒泡排序-模擬名片http://www.cnblogs.com/spring_wang/p/6112885.html
C#基礎第二天-作業答案-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112881.html
C#基礎第二天-作業-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112875.html
C#基礎第一天-作業答案http://www.cnblogs.com/spring_wang/p/6112872.html
C#基礎第一天-作業http://www.cnblogs.com/spring_wang/p/6112867.html
C#-string.Format對C#字符串格式化http://www.cnblogs.com/spring_wang/p/6077098.html