2012-02-28 59 views

回答

2

如果您打算將二維數組列表,你可以這樣做:

// Declare a list of matrices. 
List<int[,]> matrixList = new List<int[,]>(); 
// Add a matrix to the list. 
matrixList.Add(new int[5, 5]); 
+0

@naimeh:尺寸不一定必須是編譯時常量。如果你有一個'int'變量,比如'int a = int.Parse(Console.ReadLine());',可以寫'matrixList.Add(new int [a,a]);'。如果已經創建的矩陣應該能夠在運行時增長/縮小,那麼可以考慮使用列表列表,或者可能考慮使用一些自定義的「矩陣」類而不是數組。 – 2012-02-28 10:32:31

+0

我希望每個節點都有一個字符串名稱並且有一個二維數組我應該如何顯示 – naimeh 2012-02-28 10:39:27

+0

@naimeh:您應該創建自己的類(例如'Node')並在其中聲明兩個屬性:'public string Name {get;組; }'和'public int [,] Matrix {get;組; }'。類似的東西。在這種情況下,列表的聲明將爲'List list = new List ()'。 – 2012-02-28 10:48:14

相關問題