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 Werte des Zeichenfolgenwörterbuchs am angegebenen Index in eine eindimensionale Array-Instanz.
Namespace: System.Collections.Specialized
Assembly: System (in system.dll)
Syntax
'Declaration
Public Overridable Sub CopyTo ( _
array As Array, _
index As Integer _
)
'Usage
Dim instance As StringDictionary
Dim array As Array
Dim index As Integer
instance.CopyTo(array, index)
public virtual void CopyTo (
Array array,
int index
)
public:
virtual void CopyTo (
Array^ array,
int index
)
public void CopyTo (
Array array,
int index
)
public function CopyTo (
array : Array,
index : int
)
Parameter
- array
Das eindimensionale Array, das das Ziel der aus dem StringDictionary kopierten Werte ist.
- index
Der Index im Array, bei dem mit dem Kopieren begonnen wird.
Ausnahmen
| Ausnahmetyp | Bedingung |
|---|---|
array ist mehrdimensional. – oder – Die Anzahl der Elemente im StringDictionary ist größer als der verfügbare Platz zwischen dem index und dem Ende des array. |
|
array ist NULL (Nothing in Visual Basic). |
|
index ist kleiner als die untere Grenze von array. |
Hinweise
CopyTo kopiert Objekte, für die eine Typumwandlung in System.Collections.DictionaryEntry durchgeführt werden kann. DictionaryEntry enthält den Schlüssel und den Wert.
Die Elemente, die nach Array kopiert werden, werden in derselben Reihenfolge sortiert, in der der Enumerator das StringDictionary durchläuft.
Diese Methode ist ein O(n)-Vorgang, wobei n der Count ist.
Beispiel
Das folgende Codebeispiel veranschaulicht das Kopieren eines StringDictionary in ein Array.
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports Microsoft.VisualBasic
Public Class SamplesStringDictionary
Public Shared Sub Main()
' Creates and initializes a new StringDictionary.
Dim myCol As New StringDictionary()
myCol.Add("red", "rojo")
myCol.Add("green", "verde")
myCol.Add("blue", "azul")
' Displays the values in the StringDictionary.
Console.WriteLine("KEYS" + ControlChars.Tab + "VALUES in the StringDictionary")
Dim myDE As DictionaryEntry
For Each myDE In myCol
Console.WriteLine("{0}" + ControlChars.Tab + "{1}", myDE.Key, myDE.Value)
Next myDE
Console.WriteLine()
' Creates an array with DictionaryEntry elements.
Dim myArr As DictionaryEntry() = {New DictionaryEntry(), New DictionaryEntry(), New DictionaryEntry()}
' Copies the StringDictionary to the array.
myCol.CopyTo(myArr, 0)
' Displays the values in the array.
Console.WriteLine("KEYS" + ControlChars.Tab + "VALUES in the array")
Dim i As Integer
For i = 0 To myArr.Length - 1
Console.WriteLine("{0}" + ControlChars.Tab + "{1}", myArr(i).Key, myArr(i).Value)
Next i
Console.WriteLine()
End Sub 'Main
End Class 'SamplesStringDictionary
'This code produces the following output.
'
'KEYS VALUES in the StringDictionary
'green verde
'red rojo
'blue azul
'
'KEYS VALUES in the array
'green verde
'red rojo
'blue azul
using System;
using System.Collections;
using System.Collections.Specialized;
public class SamplesStringDictionary {
public static void Main() {
// Creates and initializes a new StringDictionary.
StringDictionary myCol = new StringDictionary();
myCol.Add( "red", "rojo" );
myCol.Add( "green", "verde" );
myCol.Add( "blue", "azul" );
// Displays the values in the StringDictionary.
Console.WriteLine( "KEYS\tVALUES in the StringDictionary" );
foreach ( DictionaryEntry myDE in myCol )
Console.WriteLine( "{0}\t{1}", myDE.Key, myDE.Value );
Console.WriteLine();
// Creates an array with DictionaryEntry elements.
DictionaryEntry[] myArr = { new DictionaryEntry(), new DictionaryEntry(), new DictionaryEntry() };
// Copies the StringDictionary to the array.
myCol.CopyTo( myArr, 0 );
// Displays the values in the array.
Console.WriteLine( "KEYS\tVALUES in the array" );
for ( int i = 0; i < myArr.Length; i++ )
Console.WriteLine( "{0}\t{1}", myArr[i].Key, myArr[i].Value );
Console.WriteLine();
}
}
/*
This code produces the following output.
KEYS VALUES in the StringDictionary
green verde
red rojo
blue azul
KEYS VALUES in the array
green verde
red rojo
blue azul
*/
#using <System.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
// Creates and initializes a new StringDictionary.
StringDictionary^ myCol = gcnew StringDictionary;
myCol->Add( "red", "rojo" );
myCol->Add( "green", "verde" );
myCol->Add( "blue", "azul" );
// Displays the values in the StringDictionary.
Console::WriteLine( "KEYS\tVALUES in the StringDictionary" );
IEnumerator^ myEnum = myCol->GetEnumerator();
while ( myEnum->MoveNext() )
{
DictionaryEntry^ myDE = safe_cast<DictionaryEntry^>(myEnum->Current);
Console::WriteLine( "{0}\t{1}", myDE->Key, myDE->Value );
Console::WriteLine();
// Creates an array with DictionaryEntry elements.
array<DictionaryEntry>^myArr = gcnew array<DictionaryEntry>(3);
// Copies the StringDictionary to the array.
myCol->CopyTo( myArr, 0 );
// Displays the values in the array.
Console::WriteLine( "KEYS\tVALUES in the array" );
for ( int i = 0; i < myArr->Length; i++ )
Console::WriteLine( "{0}\t{1}", myArr[ i ].Key, myArr[ i ].Value );
Console::WriteLine();
}
}
/*
This code produces the following output.
KEYS VALUES in the StringDictionary
green verde
red rojo
blue azul
KEYS VALUES in the array
green verde
red rojo
blue azul
*/
import System.* ;
import System.Collections.IEnumerator;
import System.Collections.DictionaryEntry;
import System.Collections.Specialized.* ;
public class SamplesStringDictionary
{
public static void main(String[] args)
{
// Creates and initializes a new StringDictionary.
StringDictionary myCol = new StringDictionary();
myCol.Add("red", "rojo");
myCol.Add("green", "verde");
myCol.Add("blue", "azul");
// Displays the values in the StringDictionary.
Console.WriteLine("KEYS\tVALUES in the StringDictionary");
IEnumerator objEnum = myCol.GetEnumerator();
while (objEnum.MoveNext()) {
DictionaryEntry myDE = (DictionaryEntry)objEnum.get_Current();
Console.WriteLine("{0}\t{1}", myDE.get_Key(), myDE.get_Value());
}
Console.WriteLine();
// Creates an array with DictionaryEntry elements.
DictionaryEntry myArr[] = {new DictionaryEntry(),
new DictionaryEntry(), new DictionaryEntry()};
// Copies the StringDictionary to the array.
myCol.CopyTo(myArr, 0);
// Displays the values in the array.
Console.WriteLine("KEYS\tVALUES in the array");
for (int i=0; i < myArr.length; i++) {
Console.WriteLine("{0}\t{1}", myArr[i].get_Key(),
myArr[i].get_Value());
}
Console.WriteLine();
} //main
} //SamplesStringDictionary
/*
This code produces the following output.
KEYS VALUES in the StringDictionary
green verde
red rojo
blue azul
KEYS VALUES in the array
green verde
red rojo
blue azul
*/
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
StringDictionary-Klasse
StringDictionary-Member
System.Collections.Specialized-Namespace