Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Lớp Stack trong C#


Stack dùng khi cần truy cập last-in, first-out (LIFO). Thêm = Push, xóa = Pop.

Ví dụ

using System;
using System.Collections;
namespace Demo {
    class Program {
        static void Main(string[] args) {
            Stack st = new Stack();
            st.Push('H'); st.Push('I'); st.Push('J'); st.Push('K'); st.Push('L');
            Console.WriteLine("Count: " + st.Count);
        }
    }
}

Kết quả

Count: 5