C#中通过foreach语句遍历堆栈(Stack)的代码

如下的内容段是关于C#中通过foreach语句遍历堆栈(Stack)的内容,应该能对各位也有用。

using System;
using System.Collections;
 
  public class StacksW3
  {
    static void Main(string[] args)
    {
      Stack a = new Stack(10);
      int x = 0;
 
      a.Push(x);
      x++;
      a.Push(x);
      foreach (int y in a)
      {
        Console.WriteLine(y);
      }
 
      a.Pop();
      a.Clear();
    }
  }

猜你喜欢

转载自blog.csdn.net/weixin_44201346/article/details/86519511