Exercise: Design a Stack Exercise: Design a Stack
  
  A Stack is a data structure for storing a list of elements in a LIFO
  (last in, first out) fashion. Design a class called Stack with three
  methods.

void Push(object obj)
object Pop()
void Clear()

  
  The Push() method stores the given object on top of the stack. We use
  the “object” type here so we can store any objects inside the stack.
  Remember the “object” class is the base of all classes in the .NET
  Framework. So any types can be automatically upcast to the object.
  Make sure to take into account the scenario that null is passed to
  this object. We should not store null references in the stack. So if
  null is passed to this method, you should throw an
  InvalidOperationException. Remember, when coding every method, you
  should think of all possibilities and make sure the method behaves
  properly in all these edge cases. That’s what distinguishes you from
  an “average” programmer.
  
  The Pop() method removes the object on top of the stack and returns
  it. Make sure to take into account the scenario that we call the Pop()
  method on an empty stack. In this case, this method should throw an
  InvalidOperationException. Remember, your classes should always be in
  a valid state and used properly. When they are misused, they should
  throw exceptions. Again, thinking of all these edge cases, separates
  you from an average programmer. The code written this way will be more
  robust and with less bugs.
  
  The Clear() method removes all objects from the stack.
  
  We should be able to use this stack class as follows:

var stack = new Stack();

stack.Push(1);
stack.Push(2);
stack.Push(3);

Console.WriteLine(stack.Pop());
Console.WriteLine(stack.Pop());
Console.WriteLine(stack.Pop());

  
  The output of this program will be

3
2
1



This was the task assigned to me.  Following is my code.

using System;

namespace Exercise
{
    class Program
    {
        static void Main()
        {
            var stack = new Stack();

            stack.Push(1);
            stack.Push(2);
            stack.Push(3);

            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Exercise
{
    internal class Stack : IEnumerable
    {
        private object _object;
        private List&lt;object&gt; list = new List&lt;object&gt;();

        public IEnumerator GetEnumerator()
        {
            while (list.Any())
                yield return Pop();
        }

        internal object Pop()
        {
            if (list.Count == 0)
                throw new InvalidOperationException("Cannot use .Pop() if list count equals 0.");

            _object = list.FirstOrDefault();

            list.RemoveAt(0);

            return _object;
        }

        internal void Push(object obj)
        {
            _object = obj;

            if (_object == null)
                throw new InvalidOperationException("Cannot use .Push() if object is null.");

            list.Insert(0, _object);
        }

        internal void Clear()
        {
            if (list.Count == 0)
                throw new InvalidOperationException("Cannot use .Clear() if list is empty.");

            list.Clear();
        }

        public void Print()
        {
            if (list.Count == 0)
                throw new InvalidOperationException("Stack is empty.");

            foreach (var s in list)
            {
                Console.WriteLine(s);
            }
        }
    }
}


I'm a beginner in C#.  Is there anything left to improve on with this that is within the boundaries of what the instructions expect?  Any advice or suggestions if anything to teach me something new would be great.  Thank you for all the help so far on this site.
Questions:


Why do you use the class field _object? Does it serve any real purpose that a method-local variable cannot?
Why do you implement IEnumerable?
(only consider this if you have a decent understanding of concurrency issues, and want to practice) How can you make this code thread-safe?


Suggestions:


Several method throw exceptions in unexceptionable scenarios. Why do you blow up if I want to print or clear an empty stack? That's like having the waiter shoot herself if I try to order food right as the kitchen has closed.
When you're done with the exercise, consider making your stack generic. Casting from object is so old-school C#.
Consider improving your error messages. For one, "Cannot use .Pop() if list count equals 0." could be something like: "Cannot pop an element off an empty stack".