WizardStepCollection.CopyTo(WizardStepBase[], Int32) 方法

定义

WizardStepCollection 集合中的所有项复制到兼容的、WizardStepBase 对象的一维数组,从目标数组的指定索引处开始。

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)

参数

array
WizardStepBase[]

一个从零开始的 WizardStepBase 对象的数组,用于接收从集合复制的项。

index
Int32

目标数组中该数组开始接收复制项的位置。

示例

下面的示例演示如何使用 CopyTo 该方法将对象从集合复制到 WizardStepBase 数组。 然后循环访问数组以显示 ID 每个 WizardStepBase派生对象的属性。 请注意,在该示例中, WizardSteps 控件的属性 Wizard 是类的 WizardStepCollection 实例。

<%@ 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>

注解

CopyTo使用该方法将集合的内容复制到指定的从零开始的数组中。 从目标数组的指定索引处开始复制项。 项进入数组后,可以使用数组语法访问集合中的 WizardStepCollection 项。

作为替代方法,还可以使用 GetEnumerator 该方法创建可用于访问集合中的项的枚举器。

适用于

另请参阅