Hashtable.CopyTo メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Hashtable Dim array As Array Dim arrayIndex As Integer instance.CopyTo(array, arrayIndex)


要素は、列挙子が Hashtable を反復処理するのと同じ順序で、Array にコピーされます。
Hashtable 内のキーだけをコピーするには、Hashtable.Keys.CopyTo を使用します。

1 次元の Array に Hashtable 内のキーまたは値のリストをコピーする方法の例を次に示します。
Imports System Imports System.Collections Public Class SamplesHashtable Public Shared Sub Main() ' Creates and initializes the source Hashtable. Dim mySourceHT As New Hashtable() mySourceHT.Add("A", "valueA") mySourceHT.Add("B", "valueB") ' Creates and initializes the one-dimensional target Array. Dim myTargetArray(14) As String myTargetArray(0) = "The" myTargetArray(1) = "quick" myTargetArray(2) = "brown" myTargetArray(3) = "fox" myTargetArray(4) = "jumped" myTargetArray(5) = "over" myTargetArray(6) = "the" myTargetArray(7) = "lazy" myTargetArray(8) = "dog" ' Displays the values of the target Array. Console.WriteLine("The target Array contains the following before:") PrintValues(myTargetArray, " "c) ' Copies the keys in the source Hashtable to the target Hashtable, starting at index 6. Console.WriteLine("After copying the keys, starting at index 6:") mySourceHT.Keys.CopyTo(myTargetArray, 6) ' Displays the values of the target Array. PrintValues(myTargetArray, " "c) ' Copies the values in the source Hashtable to the target Hashtable, starting at index 6. Console.WriteLine("After copying the values, starting at index 6:") mySourceHT.Values.CopyTo(myTargetArray, 6) ' Displays the values of the target Array. PrintValues(myTargetArray, " "c) End Sub 'Main Public Shared Sub PrintValues(myArr() As String, mySeparator As Char) Dim i As Integer For i = 0 To myArr.Length - 1 Console.Write("{0}{1}", mySeparator, myArr(i)) Next i Console.WriteLine() End Sub 'PrintValues End Class 'SamplesHashtable ' This code produces the following output. ' ' The target Array contains the following before: ' The quick brown fox jumped over the lazy dog ' After copying the keys, starting at index 6: ' The quick brown fox jumped over B A dog ' After copying the values, starting at index 6: ' The quick brown fox jumped over valueB valueA dog
using System; using System.Collections; public class SamplesHashtable { public static void Main() { // Creates and initializes the source Hashtable. Hashtable mySourceHT = new Hashtable(); mySourceHT.Add( "A", "valueA" ); mySourceHT.Add( "B", "valueB" ); // Creates and initializes the one-dimensional target Array. String[] myTargetArray = new String[15]; myTargetArray[0] = "The"; myTargetArray[1] = "quick"; myTargetArray[2] = "brown"; myTargetArray[3] = "fox"; myTargetArray[4] = "jumped"; myTargetArray[5] = "over"; myTargetArray[6] = "the"; myTargetArray[7] = "lazy"; myTargetArray[8] = "dog"; // Displays the values of the target Array. Console.WriteLine( "The target Array contains the following before:" ); PrintValues( myTargetArray, ' ' ); // Copies the keys in the source Hashtable to the target Hashtable, starting at index 6. Console.WriteLine( "After copying the keys, starting at index 6:" ); mySourceHT.Keys.CopyTo( myTargetArray, 6 ); // Displays the values of the target Array. PrintValues( myTargetArray, ' ' ); // Copies the values in the source Hashtable to the target Hashtable, starting at index 6. Console.WriteLine( "After copying the values, starting at index 6:" ); mySourceHT.Values.CopyTo( myTargetArray, 6 ); // Displays the values of the target Array. PrintValues( myTargetArray, ' ' ); } public static void PrintValues( String[] myArr, char mySeparator ) { for ( int i = 0; i < myArr.Length; i++ ) Console.Write( "{0}{1}", mySeparator, myArr[i] ); Console.WriteLine(); } } /* This code produces the following output. The target Array contains the following before: The quick brown fox jumped over the lazy dog After copying the keys, starting at index 6: The quick brown fox jumped over B A dog After copying the values, starting at index 6: The quick brown fox jumped over valueB valueA dog */
using namespace System; using namespace System::Collections; void PrintValues( array<String^>^myArr, char mySeparator ); int main() { // Creates and initializes the source Hashtable. Hashtable^ mySourceHT = gcnew Hashtable; mySourceHT->Add( "A", "valueA" ); mySourceHT->Add( "B", "valueB" ); // Creates and initializes the one-dimensional target Array. array<String^>^myTargetArray = gcnew array<String^>(15); myTargetArray[ 0 ] = "The"; myTargetArray[ 1 ] = "quick"; myTargetArray[ 2 ] = "brown"; myTargetArray[ 3 ] = "fox"; myTargetArray[ 4 ] = "jumped"; myTargetArray[ 5 ] = "over"; myTargetArray[ 6 ] = "the"; myTargetArray[ 7 ] = "lazy"; myTargetArray[ 8 ] = "dog"; // Displays the values of the target Array. Console::WriteLine( "The target Array contains the following before:" ); PrintValues( myTargetArray, ' ' ); // Copies the keys in the source Hashtable to the target Hashtable, starting at index 6. Console::WriteLine( "After copying the keys, starting at index 6:" ); mySourceHT->Keys->CopyTo( myTargetArray, 6 ); // Displays the values of the target Array. PrintValues( myTargetArray, ' ' ); // Copies the values in the source Hashtable to the target Hashtable, starting at index 6. Console::WriteLine( "After copying the values, starting at index 6:" ); mySourceHT->Values->CopyTo( myTargetArray, 6 ); // Displays the values of the target Array. PrintValues( myTargetArray, ' ' ); } void PrintValues( array<String^>^myArr, char mySeparator ) { for ( int i = 0; i < myArr->Length; i++ ) Console::Write( "{0}{1}", mySeparator, myArr[ i ] ); Console::WriteLine(); } /* This code produces the following output. The target Array contains the following before: The quick brown fox jumped over the lazy dog After copying the keys, starting at index 6: The quick brown fox jumped over B A dog After copying the values, starting at index 6: The quick brown fox jumped over valueB valueA dog */
import System.*; import System.Collections.*; public class SamplesHashtable { public static void main(String[] args) { // Creates and initializes the source Hashtable. Hashtable mySourceHT = new Hashtable(); mySourceHT.Add("A", "valueA"); mySourceHT.Add("B", "valueB"); // Creates and initializes the one-dimensional target Array. String myTargetArray[] = new String[15]; myTargetArray.set_Item(0, "The"); myTargetArray.set_Item(1, "quick"); myTargetArray.set_Item(2, "brown"); myTargetArray.set_Item(3, "fox"); myTargetArray.set_Item(4, "jumped"); myTargetArray.set_Item(5, "over"); myTargetArray.set_Item(6, "the"); myTargetArray.set_Item(7, "lazy"); myTargetArray.set_Item(8, "dog"); // Displays the values of the target Array. Console.WriteLine("The target Array contains the following before:"); PrintValues(myTargetArray, ' '); // Copies the keys in the source Hashtable to the target Hashtable, // starting at index 6. Console.WriteLine("After copying the keys, starting at index 6:"); mySourceHT.get_Keys().CopyTo(myTargetArray, 6); // Displays the values of the target Array. PrintValues(myTargetArray, ' '); // Copies the values in the source Hashtable to the target Hashtable, // starting at index 6. Console.WriteLine("After copying the values, starting at index 6:"); mySourceHT.get_Values().CopyTo(myTargetArray, 6); // Displays the values of the target Array. PrintValues(myTargetArray, ' '); } //main public static void PrintValues(String myArr[], char mySeparator) { for (int i = 0; i < myArr.length; i++) { Console.Write("{0}{1}", System.Convert.ToString(mySeparator), myArr.get_Item(i)); } Console.WriteLine(); } //PrintValues } //SamplesHashtable /* This code produces the following output. The target Array contains the following before: The quick brown fox jumped over the lazy dog After copying the keys, starting at index 6: The quick brown fox jumped over B A dog After copying the values, starting at index 6: The quick brown fox jumped over valueB valueA dog */
import System import System.Collections // Creates and initializes the source Hashtable. var mySourceHT : Hashtable = new Hashtable() mySourceHT.Add("A", "valueA") mySourceHT.Add("B", "valueB") // Creates and initializes the one-dimensional target Array. var myTargetArray : System.Array = System.Array.CreateInstance(System.String, 15) myTargetArray.SetValue("The", 0) myTargetArray.SetValue("quick", 1) myTargetArray.SetValue("brown", 2) myTargetArray.SetValue("fox", 3) myTargetArray.SetValue("jumped", 4) myTargetArray.SetValue("over", 5) myTargetArray.SetValue("the", 6) myTargetArray.SetValue("lazy", 7) myTargetArray.SetValue("dog", 8) // Displays the values of the target Array. Console.WriteLine("The target Array contains the following before:") PrintValues(myTargetArray, " ") // Copies the keys in the source Hashtable to the target Hashtable, // starting at index 6. Console.WriteLine("After copying the keys, starting at index 6:") mySourceHT.Keys.CopyTo(myTargetArray, 6) // Displays the values of the target Array. PrintValues(myTargetArray, " ") // Copies the values in the source Hashtable to the target Hashtable , // starting at index 6. Console.WriteLine("After copying the values, starting at index 6:") mySourceHT.Values.CopyTo(myTargetArray, 6) // Displays the values of the target Array. PrintValues(myTargetArray, " ") function PrintValues(myArr : System.Array, mySeparator : Char){ var myEnumerator : System.Collections.IEnumerator = myArr.GetEnumerator() var i : int = 0 var cols : int = myArr.GetLength(myArr.Rank - 1) while(myEnumerator.MoveNext()){ if(i < cols) i++ else{ Console.WriteLine() i = 1 } Console.Write("{0}{1}", mySeparator, myEnumerator.Current) } Console.WriteLine() } // This code produces the following output. // // The target Array contains the following before: // The quick brown fox jumped over the lazy dog // After copying the keys, starting at index 6: // The quick brown fox jumped over A B dog // After copying the values, starting at index 6: // The quick brown fox jumped over valueA valueB dog

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からHashtable.CopyTo メソッドを検索する場合は、下記のリンクをクリックしてください。

- Hashtable.CopyTo メソッドのページへのリンク