StringDictionary.CopyTo(Array, Int32) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Kopieert de waarden van de tekenreekswoordenlijst naar een eendimensionaal Array exemplaar op de opgegeven index.
public:
virtual void CopyTo(Array ^ array, int index);
public virtual void CopyTo(Array array, int index);
abstract member CopyTo : Array * int -> unit
override this.CopyTo : Array * int -> unit
Public Overridable Sub CopyTo (array As Array, index As Integer)
Parameters
- array
- Array
De eendimensionale Array waarde die de bestemming is van de waarden die zijn gekopieerd uit de StringDictionary.
- index
- Int32
De index in de matrix waar kopiëren begint.
Uitzonderingen
array is multidimensionaal.
– of –
Het aantal elementen in de elementen StringDictionary is groter dan de beschikbare ruimte van index tot het einde van array.
array is null.
index is kleiner dan de ondergrens van array.
Voorbeelden
In het volgende codevoorbeeld ziet u hoe een StringDictionary naar een matrix kan worden gekopieerd.
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
*/
Imports System.Collections
Imports System.Collections.Specialized
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
End Class
'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
Opmerkingen
CopyTo kopieert objecten waarnaar typecast kan worden verzonden System.Collections.DictionaryEntry. DictionaryEntry bevat zowel de sleutel als de waarde.
De elementen die naar de Array elementen zijn gekopieerd, worden in dezelfde volgorde gesorteerd als de enumerator doorloopt.StringDictionary
Deze methode is een O(n)-bewerking, waarbij n .Count