WizardStepCollection.CopyTo(WizardStepBase[], Int32) メソッド

定義

WizardStepCollection コレクション内のすべての項目を互換性のある 1 次元の 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[]

コレクションからコピーされた項目の格納先となるインデックス番号が 0 から始まる WizardStepBase オブジェクト配列。

index
Int32

コピーされた項目を受け取る配列の格納開始位置。

次の例では、メソッドを使用 CopyTo して、コレクションから配列にオブジェクトをコピー WizardStepBase する方法を示します。 その後、配列が反復処理され、各WizardStepBase派生オブジェクトのプロパティが表示されますID。 この例では、コントロールのWizardStepsWizardプロパティはクラスの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 使用して、指定した 0 から始まる配列にコレクションの内容をコピーします。 項目は、ターゲット配列の指定したインデックス位置からコピーされます。 項目が配列内にある場合は、配列構文を使用してコレクション内の項目に WizardStepCollection アクセスできます。

別の方法として、このメソッドを GetEnumerator 使用して、コレクション内の項目にアクセスするために使用できる列挙子を作成することもできます。

適用対象

こちらもご覧ください