Csharp/C Sharp by API/System.Collections.Generic/Stack

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

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();  
  }  
}