using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace queue { using System; using System.Collections; public class SamplesQueue { public static void Main() { // Creates and initializes a new Queue. Queue myQ = new Queue(); for (char c = 'a'; c <= 'z'; c++) myQ.Enqueue(c); //将一个元素添加到的末尾 Queue // Displays the properties and values of the Queue. Console.WriteLine("myQ"); Console.WriteLine("\tCount: {0}", myQ.Count); Console.Write("\tValues:"); PrintValues(myQ); Console.WriteLine($"myQ中第一个元素为{myQ.Peek()}"); //获取queue中第一个元素,但不删除第一个元素 Console.WriteLine("peek后myQ后序列如下:"); PrintValues(myQ); Console.WriteLine($"myQ中第一个元素为{myQ.Dequeue()}"); //获取queue中第一个元素,同时删除第一个元素 Console.WriteLine($"Dequeue后myQ中第一个元素为{myQ.Peek()}"); Console.WriteLine("Dequeue后myQ后序列如下:"); PrintValues(myQ); } public static void PrintValues(IEnumerable myCollection) { foreach (Object obj in myCollection) Console.Write(" {0}", obj); Console.WriteLine(); } } }
myQ
Count: 26
Values: a b c d e f g h i j k l m n o p q r s t u v w x y z
myQ中第一个元素为a
peek后myQ后序列如下:
a b c d e f g h i j k l m n o p q r s t u v w x y z
myQ中第一个元素为a
Dequeue后myQ中第一个元素为b
Dequeue后myQ后序列如下:
b c d e f g h i j k l m n o p q r s t u v w x y z
Queue类将队列实现为循环数组。 queue对象实现了在一端插入并从另一端删除(即先进先出功能)
如存在多个CCD检测情况下,每个ccd检测结果信息存储到Queue中,最后一个ccd检测完成,然后发送数据到robot(plc)等,通过Queue的Dequeue()方法来达到先进先出功能