C# System.Collections.Stack
1 using System; 2 using System.Collections; 3 public class SamplesStack { 4 5 public static void Main() { 6 7 // Creates and initializes a new Stack. 8 Stack myStack = new Stack(); 9 myStack.Push("Hello"); 10 myStack.Push("World"); 11 myStack.Push("!"); 12 13 // Displays the properties and values of the Stack. 14 Console.WriteLine( "myStack" ); 15 Console.WriteLine( "\tCount: {0}", myStack.Count ); 16 Console.Write( "\tValues:" ); 17 PrintValues( myStack ); 18 } 19 20 public static void PrintValues( IEnumerable myCollection ) { 21 foreach ( Object obj in myCollection ) 22 Console.Write( " {0}", obj ); 23 Console.WriteLine(); 24 } 25 26 } 27 28 29 /* 30 This code produces the following output. 31 32 myStack 33 Count: 3 34 Values: ! World Hello 35 */
属性
| Count | 获取 Stack 中包含的元素数。 | 
| IsSynchronized | 获取一个值,该值指示是否同步对 Stack 的访问(线程安全)。 | 
| SyncRoot | 获取可用于同步对 Stack 的访问的对象。 | 
方法
| Clear() | 从 Stack 中移除所有对象。 | 
| Clone() | 创建 Stack 的浅表副本。 | 
| Contains(Object) | 确定某元素是否在 Stack 中。 | 
| CopyTo(Array, Int32) | |
| Equals(Object) | 确定指定的对象是否等于当前对象。(Inherited from Object) | 
| GetEnumerator() | 返回 IEnumerator 的 Stack。 | 
| GetHashCode() | 作为默认哈希函数。(Inherited from Object) | 
| GetType() | 获取当前实例的 Type。(Inherited from Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(Inherited from Object) | 
| Peek() | 返回位于 Stack 顶部的对象但不将其移除。 | 
| Pop() | 移除并返回位于 Stack 顶部的对象。 | 
| Push(Object) | 将对象插入 Stack 的顶部。 | 
| Synchronized(Stack) | 返回 Stack 的同步(线程安全)包装。 | 
| ToArray() | 将 Stack 复制到新数组中。 | 
| ToString() | 返回表示当前对象的字符串。(Inherited from Object) | 
 
                    
                     
                    
                 
                    
                 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号