NET 集合之 Queue
Queue 表示对象的先进先出集合。队列在按接收顺序存储消息方面非常有用,以便于进行顺序处理。此类将队列作为循环数组实现。存储在 Queue
中的对象在一端插入,从另一端移除。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.Title = "This is a Test";
Test();
Console.ReadLine();
}
static void Test()
{
Func<string, string> select = str => str.ToUpper();
string[] names = { "a", "b", "e","e","n" };
var mynames = names.Select(select).ToArray();
var queue = new Queue();// 队列
foreach (var item in mynames)
{
queue.Enqueue(item);// 入队
}
Array.ForEach<Object>(queue.ToArray(), str => Console.WriteLine(str));
queue.Dequeue(); // 出队
Console.WriteLine("===================分隔线===================");
Array.ForEach<Object>(queue.ToArray(), str => Console.WriteLine(str));
}
}
}
output:
A
B
E
E
N
===================分隔线===================
B
E
E
N
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.Title = "This is a Test";
Test();
Console.ReadLine();
}
static void Test()
{
Func<string, string> select = str => str.ToUpper();
string[] names = { "a", "b", "e","e","n" };
var mynames = names.Select(select).ToArray();
var queue = new Queue();// 队列
foreach (var item in mynames)
{
queue.Enqueue(item);// 入队
}
Array.ForEach<Object>(queue.ToArray(), str => Console.WriteLine(str));
queue.Dequeue(); // 出队
Console.WriteLine("===================分隔线===================");
Array.ForEach<Object>(queue.ToArray(), str => Console.WriteLine(str));
}
}
}
output:
A
B
E
E
N
===================分隔线===================
B
E
E
N