Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Exercise_inheritance
- {
- class MyStack
- {
- private readonly ArrayList Stacks = new ArrayList();
- public void Push(Object obj)
- {
- if (obj != null)
- Stacks.Add(obj);
- else
- throw new InvalidOperationException("Error : Value cannot be null or empty");
- }
- public void Clear()
- {
- Stacks.RemoveRange(0, (Stacks.Count));
- }
- public Object Pop()
- {
- var len = Stacks.Count - 1;
- if (len < 0)
- throw new InvalidOperationException("Error : Empty stack");
- else
- {
- var lasEl = Stacks[len];
- Stacks.RemoveAt(len);
- return lasEl;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement