語言

TableRowCollection.Count 屬性

定義

得到 中TableRow物件TableRowCollection的數量。

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

屬性值

中物件TableRowTableRowCollection的數量。 預設值是 0。

實作

範例

以下範例示範如何利用該 Count 性質來決定 中 TableRowCollection列數。 請注意,在範例中, Rows 的 Table 性質是該 TableRowCollection 類別的一個實例。

   void Button_Click_Coord(object sender, EventArgs e) 
   {
       for (int rowNum = 0; rowNum < Table1.Rows.Count; rowNum++)
       {
           for (int cellNum = 0; 
               cellNum < Table1.Rows[cellNum].Cells.Count; cellNum++)
           {
               Table1.Rows[rowNum].Cells[cellNum].Text = 
                   String.Format("({0}, {1})", rowNum, cellNum);
           }            
       }
   }
Sub Button_Click_Coord(sender As Object, e As EventArgs)
    
    Dim rowNum As Integer
    For rowNum = 0 To Table1.Rows.Count - 1
        Dim cellNum As Integer
        For cellNum = 0 To (Table1.Rows(rowNum).Cells.Count) - 1                
            Table1.Rows(rowNum).Cells(cellNum).Text = _
                String.Format("({0}, {1})", rowNum, cellNum)
        Next
    Next
End Sub

備註

利用此性質來決定 中 的 TableRowCollection列數。 Count此性質常用於在迭代集合以確定上界時。

適用於

另請參閱