本文整理汇总了C#中System.Collections.Queue.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.CopyTo方法的具体用法?C# Queue.CopyTo怎么用?C# Queue.CopyTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.CopyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
//New Queue of Integers
Queue<int> queue = new Queue<int>();
queue.Enqueue(5);
queue.Enqueue(10);
queue.Enqueue(15);
queue.Enqueue(20);
/*Create new array with
length equal to Queue's element count*/
int[] array = new int[queue.Count];
//Copy the Queue to the Array
queue.CopyTo(array, 0);
//Loop through and display int[] in order
Console.WriteLine("Array: ");
for (int i=0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
//Loop through int array in reverse order
Console.WriteLine("Array reverse order: ");
for (int i = array.Length -1; i >= 0; i--)
{
Console.WriteLine(array[i]);
}
}
示例2: GetDirectories
public DirectoryInfo[] GetDirectories (string searchPattern, SearchOption searchOption)
{
switch (searchOption) {
case SearchOption.TopDirectoryOnly:
return GetDirectories (searchPattern);
case SearchOption.AllDirectories:
Queue workq = new Queue(GetDirectories(searchPattern));
Queue doneq = new Queue();
while (workq.Count > 0)
{
DirectoryInfo cinfo = (DirectoryInfo) workq.Dequeue();
DirectoryInfo[] cinfoDirs = cinfo.GetDirectories(searchPattern);
foreach (DirectoryInfo i in cinfoDirs) workq.Enqueue(i);
doneq.Enqueue(cinfo);
}
DirectoryInfo[] infos = new DirectoryInfo[doneq.Count];
doneq.CopyTo(infos, 0);
return infos;
default:
string msg = Locale.GetText ("Invalid enum value '{0}' for '{1}'.", searchOption, "SearchOption");
throw new ArgumentOutOfRangeException ("searchOption", msg);
}
}