Export (0) Print
Expand All

WizardStepCollection.CopyTo Method

Copies all the items from a WizardStepCollection collection to a compatible one-dimensional array of WizardStepBase objects, starting at the specified index in the target array.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public void CopyTo(
	WizardStepBase[] array,
	int index


Type: System.Web.UI.WebControls.WizardStepBase[]

A zero-based array of WizardStepBase objects that receives the items copied from the collection.

Type: System.Int32

The position in the target array at which the array starts receiving the copied items.

Use the CopyTo method to copy the contents of the collection into the specified zero-based array. Items are copied starting at the specified index of the target array. After the items are in an array, you can use array syntax to access the items in the WizardStepCollection collection.

As an alternative, you can also use the GetEnumerator method to create an enumerator that can be used to access the items in the collection.

The following example demonstrates how to use the CopyTo method to copy the WizardStepBase objects from the collection to an array. The array is then iterated through to display the ID property of each WizardStepBase-derived object. Note that in the example, the WizardSteps property of the Wizard control is an instance of the WizardStepCollection class.

<%@ 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 />";



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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft