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

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

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

new Stack<T>()

 
using System;        
using System.Collections.Generic;

class MainClass
{
    public static void Main(string[] args)
    {
        Stack<MyClass> stack = new Stack<MyClass>();
        stack.Push(new MyClass());
        MyClass ass3 = stack.Pop();
        Console.WriteLine("\nPopped from stack: {0}", ass3);
    }
}
class MyClass {
    
   public override string ToString(){
    
      return "my class";
   }
    
}


Stack.Pop

 
  
using System;  
using System.Collections.Generic;  
   
class MainClass {  
  public static void Main() {  
    Stack<string> st = new Stack<string>();  
  
    st.Push("One");  
    st.Push("Two");  
    st.Push("Three");  
    st.Push("Four");  
    st.Push("Five");  
 
    while(st.Count > 0) { 
      string str = st.Pop(); 
      Console.Write(str + " "); 
    } 
 
    Console.WriteLine();  
  }  
}


Stack.Push

 
  
using System;  
using System.Collections.Generic;  
   
class MainClass {  
  public static void Main() {  
    Stack<string> st = new Stack<string>();  
  
    st.Push("One");  
    st.Push("Two");  
    st.Push("Three");  
    st.Push("Four");  
    st.Push("Five");  
 
    while(st.Count > 0) { 
      string str = st.Pop(); 
      Console.Write(str + " "); 
    } 
 
    Console.WriteLine();  
  }  
}