Re: [問題] 如何用C#寫一個動態陣列?
※ 引述《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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 9 之 13 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章