最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#內(nèi)置隊(duì)列類(lèi)Queue用法實(shí)例

 更新時(shí)間:2015年04月29日 10:42:15   作者:八大山人  
這篇文章主要介紹了C#內(nèi)置隊(duì)列類(lèi)Queue用法,實(shí)例分析了C#內(nèi)置隊(duì)列的添加、移除等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了C#內(nèi)置隊(duì)列類(lèi)Queue用法。分享給大家供大家參考。具體分析如下:

這里詳細(xì)演示了C#內(nèi)置的隊(duì)列如何進(jìn)行添加,移除等功能。

using System;
using System.Collections.Generic;
class Example
{
 public static void Main()
 {
  Queue<string> numbers = new Queue<string>();
  numbers.Enqueue("one");
  numbers.Enqueue("two");
  numbers.Enqueue("three");
  numbers.Enqueue("four");
  numbers.Enqueue("five");
  // A queue can be enumerated without disturbing its contents.
  foreach( string number in numbers )
  {
   Console.WriteLine(number);
  }
  Console.WriteLine("\nDequeuing '{0}'", numbers.Dequeue());
  Console.WriteLine("Peek at next item to dequeue: {0}", 
   numbers.Peek());
  Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue());
  // Create a copy of the queue, using the ToArray method and the
  // constructor that accepts an IEnumerable<T>.
  Queue<string> queueCopy = new Queue<string>(numbers.ToArray());
  Console.WriteLine("\nContents of the first copy:");
  foreach( string number in queueCopy )
  {
   Console.WriteLine(number);
  }
  // Create an array twice the size of the queue and copy the
  // elements of the queue, starting at the middle of the 
  // array. 
  string[] array2 = new string[numbers.Count * 2];
  numbers.CopyTo(array2, numbers.Count);
  // Create a second queue, using the constructor that accepts an
  // IEnumerable(Of T).
  Queue<string> queueCopy2 = new Queue<string>(array2);
  Console.WriteLine("\nContents of the second copy, with duplicates and nulls:");
  foreach( string number in queueCopy2 )
  {
   Console.WriteLine(number);
  }
  Console.WriteLine("\nqueueCopy.Contains(\"four\") = {0}", 
   queueCopy.Contains("four"));
  Console.WriteLine("\nqueueCopy.Clear()");
  queueCopy.Clear();
  Console.WriteLine("\nqueueCopy.Count = {0}", queueCopy.Count);
 }
}
/* This code example produces the following output:
one
two
three
four
five
Dequeuing 'one'
Peek at next item to dequeue: two
Dequeuing 'two'
Contents of the copy:
three
four
five
Contents of the second copy, with duplicates and nulls:
three
four
five
queueCopy.Contains("four") = True
queueCopy.Clear()
queueCopy.Count = 0
 */

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

黎川县| 桐城市| 如皋市| 偏关县| 永平县| 太原市| 磐安县| 灵宝市| 化州市| 林芝县| 平昌县| 博湖县| 景宁| 凤城市| 建湖县| 肇东市| 铜山县| 芮城县| 博客| 伽师县| 九龙坡区| 保山市| 叙永县| 呼玛县| 旺苍县| 昌吉市| 乌拉特后旗| 淮北市| 游戏| 永吉县| 镇坪县| 株洲市| 正定县| 金塔县| 揭东县| 饶阳县| 新郑市| 庆城县| 牟定县| 耿马| 南乐县|