stack pop and takewhile
-
can someone tell me why stack.takewhile does not pop the items taken?
Stack<int> mystack = new Stack<int>(Enumerable.Range(1, 5));
mystack.TakeWhile(i => i > 3).ToList().ForEach(i => Console.WriteLine(i));
Console.WriteLine(mystack.Peek());outputs 5 4 5 i would expect the last peek to give me 3. ( obviously i'm missing something but what is it? )
-
can someone tell me why stack.takewhile does not pop the items taken?
Stack<int> mystack = new Stack<int>(Enumerable.Range(1, 5));
mystack.TakeWhile(i => i > 3).ToList().ForEach(i => Console.WriteLine(i));
Console.WriteLine(mystack.Peek());outputs 5 4 5 i would expect the last peek to give me 3. ( obviously i'm missing something but what is it? )
Why would it? TakeWhile is a LINQ extension on Enumerable. It knows nothing about stacks.
-
Why would it? TakeWhile is a LINQ extension on Enumerable. It knows nothing about stacks.