Skip to main content

C#: Program #45 (Stack)

using System;
using System.Collections;
namespace StackCode
{
    class Program
    {
        static void Main(string[] args)
        {
            Stack obj = new Stack();
            obj.Push(56);
            obj.Push(78);
            obj.Push(99);
            obj.Push(44);
            Console.WriteLine("What is on the top of the stack {0}",obj.Peek());
            Console.WriteLine("Is 45 part of the stack",obj.Contains(45));
            Console.WriteLine(obj.Pop());
            Console.WriteLine("The stack contains:");
            foreach (object o in obj)
            {
                Console.WriteLine(o);
            }
            Console.ReadKey();
        }
    }
}

Comments

Popular posts from this blog