我的博客

asp.net 自学笔记及开发过程中的经验、技巧、摘录
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C# 集合类(二):Queue

Posted on 2008-07-23 15:48  Net_Learner  阅读(242)  评论(0编辑  收藏  举报
Queue:队列,表示对象的先进先出集合。Enqueue方法入队列,Dequeue方法出队列。
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
    
class Program
    
{
        
static void Main(string[] args)
        
{
            Queue qu 
= new Queue();
            Queue qu2 
= new Queue();
            
foreach (int i in new int[41234 })
            
{
                qu.Enqueue(i);
//入队
                qu2.Enqueue(i);
            }


            
foreach (int i in qu)
            
{
                Console.WriteLine(i);
//遍历
            }


            qu.Dequeue();
//出队
            Console.WriteLine("Dequeue");
            
foreach (int i in qu)
            
{
                Console.WriteLine(i);
            }


            qu2.Peek();
//返回位于 Queue 开始处的对象但不将其移除。
            Console.WriteLine("Peek");
            
foreach (int i in qu2)
            
{
                Console.WriteLine(i);
            }

        }

    }

}