Queue先進先出,去超商時服務人員會依照順序結帳
using log4net;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
/// <summary>
/// Logger
/// </summary>
private static readonly ILog LOG = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.Name);
private Stack<String> stack = new Stack<string>();
private Queue<String> queue = new Queue<string>();
private readonly String[] ARRAY = new String[] { "王小名", "白獅獅", "大鯨魚" };
public Form1()
{
InitializeComponent();
//初始化Log4Net
log4net.Config.XmlConfigurator.Configure();
var index = 0;
foreach (var a in ARRAY)
{
stack.Push(a);
queue.Enqueue(a);
LOG.Info(String.Format("第{0}個加入{1}", ++index, a));
}
index = 0;
LOG.Info("Stack");
while (stack.Count > 0)
{
LOG.Info(String.Format("第{0}個移出{1}", ++index, stack.Pop()));
}
index = 0;
LOG.Info("Queue");
while (queue.Count > 0)
{
LOG.Info(String.Format("第{0}個移出{1}", ++index, queue.Dequeue()));
}
}
}
}