ホームページ  >  記事  >  バックエンド開発  >  C# スタック

C# スタック

黄舟
黄舟オリジナル
2016-12-27 14:27:431118ブラウズ

スタックは、オブジェクトの後入れ先出しのコレクションを表します。

C# スタック

using System;
using System.Collections; 
namespace CollectionsApplication
{    
class Program    
{        
static void Main(string[] args)        
{            
Stack st = new Stack();            
 st.Push('A');            
 st.Push('M');            
 st.Push('G');            
 st.Push('W');                         
 Console.WriteLine("Current stack: ");           
 foreach (char c in st)            
 {                
 Console.Write(c + " ");           
  }            
  Console.WriteLine();                         
  st.Push('V');           
   st.Push('H');           
    Console.WriteLine("The next poppable value in stack: {0}",             
    st.Peek());           
     Console.WriteLine("Current stack: ");                      
      foreach (char c in st)           
       {               
       Console.Write(c + " ");           
        }           
         Console.WriteLine();             
         Console.WriteLine("Removing values ");            
         st.Pop();            
         st.Pop();            
         st.Pop();                         
         Console.WriteLine("Current stack: ");            
         foreach (char c in st)            
         {               
         Console.Write(c + " ");            
         }        
         }    
         }}

上記は C# スタックの内容です。その他の関連コンテンツについては、PHP 中国語 Web サイト (www.php.cn) に注目してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。