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