Aracılığıyla paylaş


HtmlTableCellCollection.GetEnumerator Yöntem

Tanım

IEnumeratorKoleksiyondaki HtmlTableCellCollection tüm HtmlTableCell nesneleri içeren -implemented nesnesini döndürür.

public:
 virtual System::Collections::IEnumerator ^ GetEnumerator();
public System.Collections.IEnumerator GetEnumerator();
abstract member GetEnumerator : unit -> System.Collections.IEnumerator
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Function GetEnumerator () As IEnumerator

Döndürülenler

IEnumeratoriçindeki HtmlTableCellCollectiontüm HtmlTableCell nesneleri içeren bir -implemented nesnesi.

Uygulamalar

Örnekler

Aşağıdaki kod örneğinde yöntemini kullanarak GetEnumerator -implemented nesnesi oluşturma System.Collections.IEnumeratorişlemi gösterilmektedir. Nesne daha sonra koleksiyonun içeriğini HtmlTableCellCollection görüntülemek için yinelenir.

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Button_Click(Object sender, EventArgs e)
  {

    HtmlTableCell current_cell;

    // Create an IEnumerator instance.
    IEnumerator myEnum = Table1.Rows[0].Cells.GetEnumerator();

    Span1.InnerText = "The items in the first row are: ";

    // Iterate through the IEnumerator and display its contents.
    while (myEnum.MoveNext())
    {

      current_cell = (HtmlTableCell)myEnum.Current;
      Span1.InnerText = Span1.InnerText + " " + current_cell.InnerText;

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableCellCollection Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTableCellCollection Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black"
             runat="server">

         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
         </tr>
         <tr>
            <td>
               Cell 3
            </td>
            <td>
               Cell 4
            </td>
         </tr>

      </table>

      <br /><br />
  
      <input type="button" 
             value="Display the contents of the first row"
             onserverclick="Button_Click" 
             runat="server"/>

      <br /><br />

      <span id="Span1"
            runat="server"/>

   </form>

</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  
  Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
 
    Dim current_cell As HtmlTableCell

    ' Create an IEnumerator instance.
    Dim myEnum As IEnumerator = Table1.Rows(0).Cells.GetEnumerator()

    Span1.InnerText = "The items in the first row are: "

    ' Iterate through the IEnumerator and display its contents.
    While myEnum.MoveNext()
         
      current_cell = CType(myEnum.Current, HtmlTableCell)
      Span1.InnerText = Span1.InnerText & " " & current_cell.InnerText

    End While

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableCellCollection Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTableCellCollection Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black"
             runat="server">

         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
         </tr>
         <tr>
            <td>
               Cell 3
            </td>
            <td>
               Cell 4
            </td>
         </tr>

      </table>

      <br /><br />
  
      <input type="button" 
             value="Display the contents of the first row"
             onserverclick="Button_Click" 
             runat="server"/>

      <br /><br />

      <span id="Span1"
            runat="server"/>

   </form>

</body>
</html>

Açıklamalar

Koleksiyondaki HtmlTableCellCollection her öğenin içeriğini almak için yinelenebilen bir System.Collections.IEnumerator-implemented nesnesi oluşturmak için bu yöntemi kullanın.

Koleksiyonda IEnumerator.Current şu anda işaret edilen öğeyi almak için özelliğini kullanın.

IEnumerator.MoveNext yöntemini kullanarak koleksiyondaki bir sonraki öğeye geçin.

Numaralandırıcıyı IEnumerator.Reset başlangıç konumuna taşımak için yöntemini kullanın.

Uyarı

IEnumerator.MoveNext yöntemi, -implemented nesnesi oluşturulduktan System.Collections.IEnumeratorsonra veya numaralandırıcıyı koleksiyondaki ilk öğeye taşımak için yöntemini kullandıktan IEnumerator.Reset sonra çağrılmalıdır. Aksi takdirde, özelliği tarafından IEnumerator.Current temsil edilen öğe tanımlanmamıştır.

Şunlara uygulanır

Ayrıca bkz.