本文整理汇总了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