2012-04-05 77 views
0

我需要在c#中獲取填充行(填充行意味着一行至少包含一個1)的二維int數組長度。 For ex ..如何在c#中獲取二維int數組的填充行長度

1 1 1 0 1 
0 1 1 1 1 
1 1 1 1 1 
0 0 0 0 0 

現在填充行長度= 3和col = 4。 這就是我需要的...

+0

@ganesh我們可以看到你是新到SO。 當你發佈你的一些努力(代碼)時,你可以期待同行的回答。 如果你沒有發佈你的努力,那麼包括我在內的同齡人只是假設你沒有嘗試過任何事情。 – Devjosh 2012-04-05 08:30:43

回答

0

我期待着您將這些值存儲在二維整數數組中,例如

int[][] a = {new int[] {1, 1, 0, 1}, new int[] {0, 1, 1, 1}, new int[] {1, 1, 1, 1}, new int[] {0, 0, 0, 0}}; 

以下是LINQ計數行具有ATLEAST一個1

int filledRowsCount = a.Count(i => i.Any(ii => ii == 1)); 
+0

我正在使用該數組像,數組intArray = Array.CreateInstance(typeof(int),maxRow,maxCol); int [,] arrCheck1 =(int [,])intArray; – 2012-04-05 10:00:14

0
int[][] intarray = { new int[] { 1, 2, 3 }, 
         new int[] { 1, 2, 3 }, 
         new int[] { 1, 2, 3 }, 
         new int[] { 1, 2, 3 } }; 
    **int c = intarray.Count();**//for rows Length = 4 
     int b = intarray[0].Count();//for columns length =3 

你也可以使用:

 int d = intarray.GetLength(0);//for rows length = 4 
+0

他的問題是特定於查找包含至少一個1的行 – 2012-04-05 09:57:09