本文整理匯總了C#中System.Collections.Hashtable.CopyTo方法的典型用法代碼示例。如果您正苦於以下問題:C# Hashtable.CopyTo方法的具體用法?C# Hashtable.CopyTo怎麽用?C# Hashtable.CopyTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Collections.Hashtable
的用法示例。
在下文中一共展示了Hashtable.CopyTo方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Collections;
public class SamplesHashtable
{
public static void Main()
{
// Creates and initializes the source Hashtable.
var mySourceHT = new Hashtable();
mySourceHT.Add("A", "valueA");
mySourceHT.Add("B", "valueB");
// Creates and initializes the one-dimensional target Array.
var myTargetArray = new String[15];
myTargetArray[0] = "The";
myTargetArray[1] = "quick";
myTargetArray[2] = "brown";
myTargetArray[3] = "fox";
myTargetArray[4] = "jumps";
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($"{mySeparator}{myArr[i]}");
Console.WriteLine();
}
}
輸出:
The target Array contains the following before: The quick brown fox jumps over the lazy dog After copying the keys, starting at index 6: The quick brown fox jumps over B A dog After copying the values, starting at index 6: The quick brown fox jumps over valueB valueA dog