Stack क्लास में कितने एलिमेंट्स जोड़े गए हैं, यह जानने के लिए आपको Count गुण का उपयोग करना होगा।
आइए पहले स्टैक में एलिमेंट्स जोड़ें:
Stack st = new Stack(); st.Push('H'); st.Push('I'); st.Push('J'); st.Push('K'); st.Push('L'); st.Push('M'); st.Push('N'); st.Push('O');अब स्टैक में एलिमेंट्स की संख्या गिनें:
Console.WriteLine("Count: "+st.Count);आइए पूरा कोड देखें:
उदाहरण
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'); st.Push('M'); st.Push('N'); st.Push('O'); Console.WriteLine("Count: "+st.Count); } } }आउटपुट
Count: 8