public int pop() { if (S1.Count == 0) { throw new Exception("No more items to return"); } //1 while (S1.Count != 0) { S2.Push(S1.Pop()); } //2 var popvalue = S2.Pop(); //3 while (S2.Count != 0) { S1.Push(S2.Pop()); } return(int.Parse(popvalue.ToString())); }