Demo.GeneralPurposeStack.Push C# (CSharp) Method

Push() public method

public Push ( object data ) : void
data object
return void
        public void Push(object data)
        {
            if (this.currentPosition >= this.stackArr.GetUpperBound(0))
            {
                throw new Exception("Can't take any more. Stack is full!!");
            }
            this.currentPosition = this.currentPosition + 1;
            this.stackArr[this.currentPosition] = data;
        }

Usage Example

        static void GenericExplanation()
        {
            IntegerStack iStack = new IntegerStack(5);

               iStack.Push(0);
               iStack.Push(100);
               iStack.Push(1000);

               int element = iStack.Pop();
               Console.WriteLine(element);

               element = iStack.Pop();
               Console.WriteLine(element);

               element = iStack.Pop();
               Console.WriteLine(element);

               GeneralPurposeStack gStack = new GeneralPurposeStack(5);

               gStack.Push("ABCD");
               gStack.Push("jj");
               gStack.Push("kk");

               string element1 = (string) gStack.Pop();

            GenericStack<int> genericIntStack = new GenericStack<int>(5);

            genericIntStack.Push(0);
            genericIntStack.Push(1);

            int element22 = genericIntStack.Pop();
            Console.WriteLine(element);

            element = genericIntStack.Pop();
            Console.WriteLine(element);

            GenericStack<Person> pStack = new GenericStack<Person>(5);

            pStack.Push(new Person { FirstName = "ABCD" });
            pStack.Push(new Person { FirstName = "DEFG" });

            Person element122 = pStack.Pop();
            Console.WriteLine(element122.FirstName);

            element122 = pStack.Pop();
            Console.WriteLine(element122.FirstName);
        }