国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#內置隊列類Queue用法實例

2020-01-24 01:53:44
字體:
來源:轉載
供稿:網友

本文實例講述了C#內置隊列類Queue用法。分享給大家供大家參考。具體分析如下:

這里詳細演示了C#內置的隊列如何進行添加,移除等功能。

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:onetwothreefourfiveDequeuing 'one'Peek at next item to dequeue: twoDequeuing 'two'Contents of the copy:threefourfiveContents of the second copy, with duplicates and nulls:threefourfivequeueCopy.Contains("four") = TruequeueCopy.Clear()queueCopy.Count = 0 */

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长岛县| 海门市| 玉树县| 达孜县| 密山市| 玉屏| 江门市| 潜江市| 阿拉善右旗| 常山县| 筠连县| 佛冈县| 东至县| 东港市| 香港 | 竹北市| 九龙坡区| 哈尔滨市| 新蔡县| 峡江县| 疏附县| 且末县| 峨眉山市| 绥宁县| 宁南县| 宣化县| 灵璧县| 读书| 寻乌县| 聂拉木县| 昂仁县| 崇阳县| 景东| 巴楚县| 江西省| 屏山县| 天津市| 宕昌县| 呼图壁县| 松阳县| 章丘市|