本文實例講述了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(); }}
希望本文所述對大家的C#程序設計有所幫助。
新聞熱點
疑難解答