WizardStepCollection.CopyTo(WizardStepBase[], Int32) Método

Definição

Copia todos os itens de uma coleção WizardStepCollection para uma matriz unidimensional compatível de objetos WizardStepBase, iniciando no índice especificado na matriz de destino.

public:
 void CopyTo(cli::array <System::Web::UI::WebControls::WizardStepBase ^> ^ array, int index);
public void CopyTo (System.Web.UI.WebControls.WizardStepBase[] array, int index);
member this.CopyTo : System.Web.UI.WebControls.WizardStepBase[] * int -> unit
Public Sub CopyTo (array As WizardStepBase(), index As Integer)

Parâmetros

array
WizardStepBase[]

Uma matriz de base zero de objetos WizardStepBase que recebe os itens copiados da coleção.

index
Int32

A posição na matriz de destino na qual a matriz começa a receber os itens copiados.

Exemplos

O exemplo a seguir demonstra como usar o CopyTo método para copiar os WizardStepBase objetos da coleção para uma matriz. Em seguida, a matriz é iterada para exibir a ID propriedade de cada WizardStepBaseobjeto derivado. Observe que, no exemplo, a WizardSteps propriedade do Wizard controle é uma instância da WizardStepCollection classe.

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

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

<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {

    // Declare an array of WizardStepBase objects.
    WizardStepBase[] stepArray = new WizardStepBase[Wizard1.WizardSteps.Count];

    // Use the CopyTo method to copy the WizardStep items 
    // of the Wizard control into the array.
    Wizard1.WizardSteps.CopyTo(stepArray, 0);
    
    // Display the WizardStep items.
    Message.Text = "The WizardStepBase items of the Wizard1 control are: <br/><br/>";
    
    for (int i = 0; i < stepArray.Length; i++)
    {
      Message.Text += stepArray[i].ID + "<br />";
    }

  }


</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:Wizard id="Wizard1" 
        runat="server" >
        <WizardSteps>
          <asp:WizardStep id="WizardStep1" 
            runat="server" 
            title="Step 1">
          </asp:WizardStep>
          <asp:WizardStep id="WizardStep2" 
            runat="server" 
            title="Step 2">
          </asp:WizardStep>
          <asp:WizardStep id="WizardStep3" 
            runat="server" 
            title="Step 3">
          </asp:WizardStep>
        </WizardSteps>
        <HeaderTemplate>
          <b>WizardStepCollection CopyTo Example</b>
        </HeaderTemplate>
      </asp:Wizard>
      <asp:label id="Message" 
        runat="server"/>
    </form>
  </body>
</html>
<%@ Page Language="VB" %>

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

<script runat="server">
  
  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' Declare an array of WizardStepBase objects.
    Dim stepArray(Wizard1.WizardSteps.Count - 1) As WizardStep

    ' Use the CopyTo method to copy the WizardStep items 
    ' of the Wizard control into the array.
    Wizard1.WizardSteps.CopyTo(stepArray, 0)
    
    ' Display the WizardStep items.
    Message.Text = "The WizardStepBase items of the Wizard1 control are: <br/><br/>"
    
    For i As Integer = 0 To stepArray.Length - 1
      Message.Text &= stepArray(i).ID & "<br />"
    Next

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:Wizard id="Wizard1" 
        runat="server" >
        <WizardSteps>
          <asp:WizardStep id="WizardStep1" 
            runat="server" 
            title="Step 1">
          </asp:WizardStep>
          <asp:WizardStep id="WizardStep2" 
            runat="server" 
            title="Step 2">
          </asp:WizardStep>
          <asp:WizardStep id="WizardStep3" 
            runat="server" 
            title="Step 3">
          </asp:WizardStep>
        </WizardSteps>
        <HeaderTemplate>
          <b>WizardStepCollection CopyTo Example</b>
        </HeaderTemplate>
      </asp:Wizard>
      <asp:label id="Message" 
        runat="server"/>
    </form>
  </body>
</html>

Comentários

Use o CopyTo método para copiar o conteúdo da coleção para a matriz baseada em zero especificada. Os itens são copiados a partir do índice especificado da matriz de destino. Depois que os itens estiverem em uma matriz, você poderá usar a sintaxe de matriz para acessar os itens na WizardStepCollection coleção.

Como alternativa, você também pode usar o GetEnumerator método para criar um enumerador que pode ser usado para acessar os itens na coleção.

Aplica-se a

Confira também