Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Kopiert die SortedList-Elemente an den angegebenen Index in einer eindimensionalen Array-Instanz.
Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Overridable Sub CopyTo ( _
array As Array, _
arrayIndex As Integer _
)
'Usage
Dim instance As SortedList
Dim array As Array
Dim arrayIndex As Integer
instance.CopyTo(array, arrayIndex)
public virtual void CopyTo (
Array array,
int arrayIndex
)
public:
virtual void CopyTo (
Array^ array,
int arrayIndex
)
public void CopyTo (
Array array,
int arrayIndex
)
public function CopyTo (
array : Array,
arrayIndex : int
)
Parameter
- array
Das eindimensionale Array, das das Ziel der aus SortedList kopierten DictionaryEntry-Objekte ist. Für Array muss eine nullbasierte Indizierung verwendet werden.
- arrayIndex
Der nullbasierte Index in array, ab dem kopiert wird.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
array ist NULL (Nothing in Visual Basic). |
|
arrayIndex ist kleiner als null. |
|
array ist mehrdimensional. – oder – arrayIndex ist größer oder gleich der Länge von array. – oder – Die Anzahl der aus der Quell-SortedList zu kopierenden Elemente ist größer als der verfügbare Platz von arrayIndex bis zum Ende des Ziel-array. |
|
Der Typ der Quell-SortedList kann nicht automatisch in den Typ des Ziel-array umgewandelt werden. |
Hinweise
Die Schlüssel-Wert-Paare werden in derselben Reihenfolge in das Array kopiert, in der der Enumerator die SortedList durchläuft.
Verwenden Sie SortedList.Keys.CopyTo, wenn Sie lediglich die Schlüssel in der SortedList kopieren möchten.
Verwenden Sie SortedList.Values.CopyTo, wenn Sie lediglich die Werte in der SortedList kopieren möchten.
Diese Methode ist eine O(n)-Operation, wobei n der Count ist.
Beispiel
Im folgenden Beispiel wird gezeigt, wie die Werte in einer SortedList in ein eindimensionales Array kopiert werden.
Imports System
Imports System.Collections
Public Class SamplesSortedList
Public Shared Sub Main()
' Creates and initializes the source SortedList.
Dim mySourceList As New SortedList()
mySourceList.Add(2, "cats")
mySourceList.Add(3, "in")
mySourceList.Add(1, "napping")
mySourceList.Add(4, "the")
mySourceList.Add(0, "three")
mySourceList.Add(5, "barn")
' Creates and initializes the one-dimensional target Array.
Dim tempArray() As String = {"The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog"}
Dim myTargetArray(14) As DictionaryEntry
Dim i As Integer = 0
Dim s As String
For Each s In tempArray
myTargetArray(i).Key = i
myTargetArray(i).Value = s
i += 1
Next s
' Displays the values of the target Array.
Console.WriteLine("The target Array contains the following (before and after copying):")
PrintValues(myTargetArray, " "c)
' Copies the entire source SortedList to the target SortedList, starting at index 6.
mySourceList.CopyTo(myTargetArray, 6)
' Displays the values of the target Array.
PrintValues(myTargetArray, " "c)
End Sub 'Main
Public Shared Sub PrintValues(myArr() As DictionaryEntry, mySeparator As Char)
Dim i As Integer
For i = 0 To myArr.Length - 1
Console.Write("{0}{1}", mySeparator, myArr(i).Value)
Next i
Console.WriteLine()
End Sub 'PrintValues
End Class 'SamplesSortedList
'This code produces the following output.
'
'The target Array contains the following (before and after copying):
' The quick brown fox jumped over the lazy dog
' The quick brown fox jumped over three napping cats in the barn
using System;
using System.Collections;
public class SamplesSortedList {
public static void Main() {
// Creates and initializes the source SortedList.
SortedList mySourceList = new SortedList();
mySourceList.Add( 2, "cats" );
mySourceList.Add( 3, "in" );
mySourceList.Add( 1, "napping" );
mySourceList.Add( 4, "the" );
mySourceList.Add( 0, "three" );
mySourceList.Add( 5, "barn" );
// Creates and initializes the one-dimensional target Array.
String[] tempArray = new String[] { "The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog" };
DictionaryEntry[] myTargetArray = new DictionaryEntry[15];
int i = 0;
foreach ( String s in tempArray ) {
myTargetArray[i].Key = i;
myTargetArray[i].Value = s;
i++;
}
// Displays the values of the target Array.
Console.WriteLine( "The target Array contains the following (before and after copying):" );
PrintValues( myTargetArray, ' ' );
// Copies the entire source SortedList to the target SortedList, starting at index 6.
mySourceList.CopyTo( myTargetArray, 6 );
// Displays the values of the target Array.
PrintValues( myTargetArray, ' ' );
}
public static void PrintValues( DictionaryEntry[] myArr, char mySeparator ) {
for ( int i = 0; i < myArr.Length; i++ )
Console.Write( "{0}{1}", mySeparator, myArr[i].Value );
Console.WriteLine();
}
}
/*
This code produces the following output.
The target Array contains the following (before and after copying):
The quick brown fox jumped over the lazy dog
The quick brown fox jumped over three napping cats in the barn
*/
using namespace System;
using namespace System::Collections;
void PrintValues( array<DictionaryEntry>^ myArr, Char mySeparator );
int main()
{
// Creates and initializes the source SortedList.
SortedList^ mySourceList = gcnew SortedList;
mySourceList->Add( 2, "cats" );
mySourceList->Add( 3, "in" );
mySourceList->Add( 1, "napping" );
mySourceList->Add( 4, "the" );
mySourceList->Add( 0, "three" );
mySourceList->Add( 5, "barn" );
// Creates and initializes the one-dimensional target Array.
array<String^>^tempArray = {"The","quick","brown","fox","jumped","over","the","lazy","dog"};
array<DictionaryEntry>^myTargetArray = gcnew array<DictionaryEntry>(15);
int i = 0;
IEnumerator^ myEnum = tempArray->GetEnumerator();
while ( myEnum->MoveNext() )
{
String^ s = safe_cast<String^>(myEnum->Current);
myTargetArray[ i ].Key = i;
myTargetArray[ i ].Value = s;
i++;
}
// Displays the values of the target Array.
Console::WriteLine( "The target Array contains the following (before and after copying):" );
PrintValues( myTargetArray, ' ' );
// Copies the entire source SortedList to the target SortedList, starting at index 6.
mySourceList->CopyTo( myTargetArray, 6 );
// Displays the values of the target Array.
PrintValues( myTargetArray, ' ' );
}
void PrintValues( array<DictionaryEntry>^ myArr, Char mySeparator )
{
for ( int i = 0; i < myArr->Length; i++ )
Console::Write( "{0}{1}", mySeparator, myArr[ i ].Value );
Console::WriteLine();
}
/*
This code produces the following output.
The target Array contains the following (before and after copying):
The quick brown fox jumped over the lazy dog
The quick brown fox jumped over three napping cats in the barn
*/
import System.*;
import System.Collections.*;
public class SamplesSortedList
{
public static void main(String[] args)
{
// Creates and initializes the source SortedList.
SortedList mySourceList = new SortedList();
mySourceList.Add((Int32)2, "cats");
mySourceList.Add((Int32)3, "in");
mySourceList.Add((Int32)1, "napping");
mySourceList.Add((Int32)4, "the");
mySourceList.Add((Int32)0, "three");
mySourceList.Add((Int32)5, "barn");
// Creates and initializes the one-dimensional target Array.
String tempArray[] = new String[] {"The", "quick", "brown", "fox",
"jumped", "over", "the", "lazy", "dog"};
DictionaryEntry myTargetArray[] = new DictionaryEntry[15];
for (int iCtr = 0; iCtr < tempArray.length; iCtr++) {
String s = tempArray[iCtr];
myTargetArray[iCtr].set_Key((Int32)iCtr);
myTargetArray[iCtr].set_Value(s);
}
// Displays the values of the target Array.
Console.WriteLine("The target Array contains the following "
+ "(before and after copying):");
PrintValues(myTargetArray, ' ');
// Copies the entire source SortedList to the target SortedList,
// starting at index 6.
mySourceList.CopyTo(myTargetArray, 6);
// Displays the values of the target Array.
PrintValues(myTargetArray, ' ');
} //main
public static void PrintValues(DictionaryEntry[] myArr, char mySeparator)
{
for (int i = 0; i < myArr.length; i++) {
Console.Write("{0}{1}",
System.Convert.ToString(mySeparator),
System.Convert.ToString(myArr[i].get_Value()));
}
Console.WriteLine();
} //PrintValues
} //SamplesSortedList
/*
This code produces the following output.
The target Array contains the following (before and after copying):
The quick brown fox jumped over the lazy dog
The quick brown fox jumped over three napping cats in the barn
*/
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0
Siehe auch
Referenz
SortedList-Klasse
SortedList-Member
System.Collections-Namespace
Array-Klasse
DictionaryEntry-Struktur
GetEnumerator