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

C#: Program #15 (For Loop)

using System; namespace Loops {     class Program     {         static void Main(string[] args)         {                         object[] information = {"Gray", "14-Arid-4052", "Rawalpindi",21,3.80};             for (int i = 0; i < information.Length; i++)             {                 Console.WriteLine("The value of index {0} is {1}",i,information[i]);             }                 Console.ReadKey();         }     } }