本文整理汇总了C#中System.Collections.SortedList.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.CopyTo方法的具体用法?C# SortedList.CopyTo怎么用?C# SortedList.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.SortedList
的用法示例。
在下文中一共展示了SortedList.CopyTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Collections;
public class SamplesSortedList {
public static void Main() {
// Creates and initializes the source SortedList.
SortedList mySourceList = new SortedList();
mySourceList.Add( 2, "cats" );
mySourceList.Add( 3, "in" );
mySourceList.Add( 1, "napping" );
mySourceList.Add( 4, "the" );
mySourceList.Add( 0, "three" );
mySourceList.Add( 5, "barn" );
// Creates and initializes the one-dimensional target Array.
String[] tempArray = new String[] { "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog" };
DictionaryEntry[] myTargetArray = new DictionaryEntry[15];
int i = 0;
foreach ( String s in tempArray ) {
myTargetArray[i].Key = i;
myTargetArray[i].Value = s;
i++;
}
// Displays the values of the target Array.
Console.WriteLine( "The target Array contains the following (before and after copying):" );
PrintValues( myTargetArray, ' ' );
// Copies the entire source SortedList to the target SortedList, starting at index 6.
mySourceList.CopyTo( myTargetArray, 6 );
// Displays the values of the target Array.
PrintValues( myTargetArray, ' ' );
}
public static void PrintValues( DictionaryEntry[] myArr, char mySeparator ) {
for ( int i = 0; i < myArr.Length; i++ )
Console.Write( "{0}{1}", mySeparator, myArr[i].Value );
Console.WriteLine();
}
}
输出:
The target Array contains the following (before and after copying): The quick brown fox jumps over the lazy dog The quick brown fox jumps over three napping cats in the barn