المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : stack pop and takewhile



C# Programming
08-26-2011, 05:22 AM
can someone tell me why stack.takewhile does not pop the items taken?



Stack mystack = new Stack(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? )