作者blackbing (blackbing)
站内C_Sharp
标题Re: [问题] 如何用C#写一个动态阵列?
时间Sat Mar 24 04:18:01 2007
※ 引述《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