TreeNodeCollection.CopyTo(Array, Int32) TreeNodeCollection.CopyTo(Array, Int32) TreeNodeCollection.CopyTo(Array, Int32) TreeNodeCollection.CopyTo(Array, Int32) Method

Definition

Kopiert die gesamte Auflistung in ein vorhandenes Array an einer angegebenen Position innerhalb des Arrays.Copies the entire collection into an existing array at a specified location within the array.

public:
 virtual void CopyTo(Array ^ dest, int index);
public void CopyTo (Array dest, int index);
abstract member CopyTo : Array * int -> unit
override this.CopyTo : Array * int -> unit
Public Sub CopyTo (dest As Array, index As Integer)

Parameter

dest
Array Array Array Array

Das Zielarray.The destination array.

index
Int32 Int32 Int32 Int32

Der Index im Zielarray, ab dem gespeichert wird.The index in the destination array at which storing begins.

Implementiert

Beispiele

Das folgende Codebeispiel zeigt die Anzahl der TreeNode Objekte in ein TreeNodeCollection, kopiert den Inhalt der Auflistung, die eine Object Array- und zeigt eine Liste der Strukturknoten in einem Label Steuerelement.The following code example displays the number of TreeNode objects in a TreeNodeCollection, copies the contents of the collection to an Object array, and displays a list of the tree nodes in a Label control. In diesem Beispiel benötigen Sie eine TreeView mit mindestens einem TreeNode in seine TreeNodeCollection, und ein Label control für eine Form.This example requires that you have a TreeView with at least one TreeNode in its TreeNodeCollection, and a Label control on a Form.

void CopyTreeNodes()
{
   // Get the collection of TreeNodes.
   TreeNodeCollection^ myNodeCollection = myTreeView->Nodes;
   int myCount = myNodeCollection->Count;
   myLabel->Text = String::Concat( myLabel->Text, "Number of nodes in the collection : ", myCount );
   myLabel->Text = String::Concat( myLabel->Text, "\n\nElements of the Array after Copying from the collection :\n" );
   
   // Create an Object array.
   array<Object^>^myArray = gcnew array<Object^>(myCount);
   
   // Copy the collection into an array.
   myNodeCollection->CopyTo( myArray, 0 );
   for ( int i = 0; i < myArray->Length; i++ )
   {
      myLabel->Text = myLabel->Text + (dynamic_cast<TreeNode^>(myArray[ i ]))->Text + "\n";

   }
}
private void CopyTreeNodes()
{
   // Get the collection of TreeNodes.
   TreeNodeCollection myNodeCollection = myTreeView.Nodes;
   int myCount = myNodeCollection.Count;

   myLabel.Text += "Number of nodes in the collection :" + myCount;
   myLabel.Text += "\n\nElements of the Array after Copying from the collection :\n";
   // Create an Object array.
   Object[] myArray = new Object[myCount];
   // Copy the collection into an array.
   myNodeCollection.CopyTo(myArray,0);
   for(int i=0; i<myArray.Length; i++)
   {
      myLabel.Text += ((TreeNode)myArray[i]).Text + "\n";
   }
}
Private Sub CopyTreeNodes()
   ' Get the collection of TreeNodes.
   Dim myNodeCollection As TreeNodeCollection = myTreeView.Nodes
   Dim myCount As Integer = myNodeCollection.Count

   myLabel.Text += "Number of nodes in the collection :" + myCount.ToString()

   myLabel.Text += ControlChars.NewLine + ControlChars.NewLine + _
     "Elements of the Array after Copying from the collection :" + ControlChars.NewLine

   ' Create an Object array.
   Dim myArray(myCount -1) As Object

   ' Copy the collection into an array.
   myNodeCollection.CopyTo(myArray, 0)
   Dim i As Integer
   For i = 0 To myArray.Length - 1
      myLabel.Text += CType(myArray(i), TreeNode).Text + ControlChars.NewLine
   Next i
End Sub

Gilt für: