Advertisement
Guest User

inheritance_exercise

a guest
Jul 20th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. namespace Exercise_inheritance
  2. {
  3.     class MyStack
  4.     {
  5.         private readonly ArrayList Stacks = new ArrayList();
  6.          
  7.         public void Push(Object obj)
  8.         {
  9.             if (obj != null)
  10.                 Stacks.Add(obj);
  11.             else
  12.                 throw new InvalidOperationException("Error : Value cannot be null or empty");
  13.         }
  14.  
  15.         public void Clear()
  16.         {
  17.             Stacks.RemoveRange(0, (Stacks.Count));
  18.         }
  19.  
  20.         public Object Pop()
  21.         {
  22.             var len = Stacks.Count - 1;
  23.             if (len < 0)
  24.                 throw new InvalidOperationException("Error : Empty stack");
  25.             else
  26.             {
  27.                 var lasEl = Stacks[len];
  28.                 Stacks.RemoveAt(len);
  29.                 return lasEl;
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement