C# Stack Count

Description

Gets the number of elements contained in the Stack.

Syntax


public int Count { get; }

Example


using System;/*from   ww w.  j a v  a  2  s. c  o m*/
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Stack<string> numbers = new Stack<string>();
        numbers.Push("one");
        numbers.Push("two");
        numbers.Push("three");
        numbers.Push("four");
        numbers.Push("five");

        Console.WriteLine("\nstack2.Count = {0}", numbers.Count);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack