Re: [問題] 如何用C#寫一個動態陣列?

看板C_Sharp (C#)作者 (blackbing)時間18年前 (2007/03/24 04:18), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串9/13 (看更多)
※ 引述《rahim (forget it)》之銘言: : ※ 引述《rahim (forget it)》之銘言: : : System.Collections.Generic裡面的類別 : :       跟ArrayList比較接近的 是List泛型類別嗎? : : http://msdn2.microsoft.com/zh-tw/library/6sh2ey19(VS.80).aspx     : 如果想要依照使用者輸入的要求 : 建立一個m X n的動態陣列  :        那下面這樣寫可以嗎? : Console.WriteLine("Please input the row size of matrix"); : int m =Convert.ToInt32(Console.ReadLine()); : Console.WriteLine("Please input the column size of matrix"); : int n = Convert.ToInt32(Console.ReadLine()); : List<List<double>> arr = new List<List<double>>(); : for (int i = 0; i < m; i++) : { : arr[i] = new List<double>(); : for (int j = 0; j < n; j++) : { : arr[i][j] = i + j; : } : }  List< > 泛型集合類別 角括弧裡頭可以接受任何型態,也就是所謂的泛型 因此泛型集合可以接受任何型態的值 Tomex版大介紹的那本書裡頭有很詳細的介紹 不過我測試了一下ArrayList()以及List<>() 執行的效率上好像沒有差很多 不知道各位大大有什麼其他的見解。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.169.0.58
文章代碼(AID): #1613NwfB (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #1613NwfB (C_Sharp)