close
static void Main(string[] args) { // [] is specific type and fixed length. // It is a data structure. String[] arr = new string[] {"Hi", "I", "am", "ALam"}; ShowMessage(arr); // List is specific type and unbounded length. // namespace is System.Collection.Generic List list = new List(); list.Add("Hi"); list.Add("I"); list.Add("am"); list.Add("Alam"); ShowMessage(list); // ArrayList is any type and undounded length. // namespace is System.Collection ArrayList arraylist = new ArrayList(); arraylist.Add("Hi"); arraylist.Add("I"); arraylist.Add("am"); arraylist.Add("Alam"); arraylist.Add(12345); // when we call the ShowMessage, it will be wrong. ShowMessage(arraylist); } private static void ShowMessage(string[] temp) { foreach (string aaa in temp) { Console.WriteLine("{0}", aaa); } Console.ReadLine(); } private static void ShowMessage(List temp) { foreach (string aaa in temp) { Console.WriteLine("{0}", aaa); } Console.ReadLine(); } private static void ShowMessage(ArrayList temp) { foreach (string aaa in temp) { Console.WriteLine("{0}", aaa); } Console.ReadLine(); } }
全站熱搜