Csharp/C Sharp by API/System.Collections/Queue — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:08, 26 мая 2010

Queue.Clear()

  

using System;
using System.Collections;
class MainClass
{
  static void Main(string[] args)
  {
    Queue a = new Queue(10);
    int x = 0;
    a.Enqueue(x);
    x++;
    a.Enqueue(x);
    foreach (int y in a)
    {
      Console.WriteLine(y);
    }
    a.Dequeue();
    a.Clear();
  }
}


Queue.Dequeue()

  
 
using System; 
using System.Collections; 
  
class MainClass { 
 
  public static void Main() { 
    Queue q = new Queue(); 
 
    q.Enqueue(1); 
    q.Enqueue(2); 
    q.Enqueue(3); 
    q.Enqueue(4); 
 
    Console.Write("queue: "); 
    foreach(int i in q) 
      Console.Write(i + " "); 
 
    Console.WriteLine();         
    Console.Write("Dequeue -> "); 
    int a = (int) q.Dequeue(); 
    Console.WriteLine(a); 
 
    Console.Write("queue: "); 
    foreach(int i in q) 
      Console.Write(i + " "); 
 
    Console.WriteLine();         
 
  } 
}


Queue.Peek()

  
using System;
using System.Collections;
using System.Collections.Specialized;
class MyClass{
   public string MyName="A";   
}
class MainClass
{
  static void Main(string[] args)
  {
    Queue classQueue = new Queue();
    classQueue.Enqueue(new MyClass());
    classQueue.Enqueue(new MyClass());
    classQueue.Enqueue(new MyClass());
    // Peek at first car in Q.
    Console.WriteLine("First in Q is {0}",
      ((MyClass)classQueue.Peek()).MyName);
  }
}