在C#中将对象添加到队列的末尾-排队操作
要将对象添加到队列的末尾,代码如下-
示例
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
Queue<string> queue = new Queue<string>();
queue.Enqueue("Electronics");
queue.Enqueue("Accessories");
queue.Enqueue("Toys");
queue.Enqueue("Books");
queue.Enqueue("Furniture");
queue.Enqueue("Clothing");
queue.Enqueue("Footwear");
queue.Enqueue("Cookware");
queue.Enqueue("Pet Supplies");
Console.WriteLine("Elements in the Queue...");
foreach(var element in queue){
Console.WriteLine(element);
}
Console.WriteLine("Do the queue has the element Books? = "+queue.Contains("Books"));
}
}输出结果
这将产生以下输出-
Elements in the Queue... Electronics Accessories Toys Books Furniture Clothing Footwear Cookware Pet Supplies Do the queue has the element Books? = True
示例
现在让我们来看另一个示例-
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
Queue<string> queue = new Queue<string>();
queue.Enqueue("Gary");
queue.Enqueue("Jack");
queue.Enqueue("Ryan");
queue.Enqueue("Kevin");
queue.Enqueue("Mark");
queue.Enqueue("Jack");
queue.Enqueue("Ryan");
queue.Enqueue("Kevin");
Console.Write("Count of elements = ");
Console.WriteLine(queue.Count);
queue.Clear();
Console.Write("Count of elements (updated) = ");
Console.WriteLine(queue.Count);
}
}输出结果
这将产生以下输出-
Count of elements = 8 Count of elements (updated) = 0
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短