What I want to accomplish is to access a method off an object that is at the top of a stack like so:
var stack = new Stack();
var obj1 = new Foo(stack); //has method called Bar, and reference to stack
stack.Push(obj1);
stack.Peek().Bar();
I want to use a stack instead of an array because the function Bar will pop itself off the stack at the end of its execution. Is there any way of doing this with a stack or will I need to result to a List? I thought Peek returns the top of the stack without popping.
See msdn resource .
Stack<T>supportsPush(),Peek()andPop().Or perhaps I am not understanding your question.