2015-04-18 31 views
0
static Array Matrix(int Rows, int Columns) 
{ 
    int[,] Lottery = new int[Rows,Columns]; 
    for (int i = 0; i < Lottery.GetLength(0); i++) 
    { 
     for (int j = 0; j < Lottery.GetLength(1); j++) 
     { 
      Lottery[i, j] = RandomNum(1, 46);  
      Console.Write("{0,3},", Lottery[i, j]); 
      Console.WriteLine(); 
     } 
     return Lottery; 
    } 
} 

我有這個功能來啓動和打印矩陣如何使用已經從一個函數在foreach循環返回數組

和我想要做一個foreach循環,檢查所有的數字在每一行,但如果我做foreach (int i in Matrix)它告訴我,我不能在一個方法組上操作,如果我做foreach (int i in Lottery)它告訴我,Lottery是一個命名空間。

我是一個新手,我不知道該怎麼辦

+0

'的foreach(INT I在矩陣中)'不正確,因爲您應該使用2個參數調用Matrix方法;嘗試'foreach(int我在Matrix(3,4))' – ASh

+0

@ASh謝謝你的回答 – Muffinator

+0

此外,你應該改變你的方法簽名來返回一個像這樣的int []:'private static int [,] Matrix (int行,int列)' – khlr

回答

2

沒有意義,呼籲像

foreach (int i in Matrix) 

,因爲矩陣是一個Funtion或方法。而且你也沒有通過該功能所需參數..

您的需求,首先準備數組,然後檢查..

做檢查這樣

Array lottery = Matrix(5, 5); 
foreach (int number in lottery) 
{ 
    // check number as required 
} 
相關問題