>>>Worked for me:
Stack<string> s = new Stack<string>();
>>> s.Push("A");
>>> s.Push("B");
>>> s.Push("C"); // C,B,A
>>> s.Reverse(); // A,B,C
>>>
>>
>>Hi Viv,
>>
>>Without the extension method - it won't work
>>
>> Stack<string> s = new Stack<string>();
>> s.Push("A");
>> s.Push("B");
>> s.Push("C"); // C,B,A
>> s.Reverse(); // A,B,C
>>
>> while (s.Count != 0)
>> {
>> Console.WriteLine(s.Pop());
>> }
>> Console.ReadLine(); // C, B, A
>>
>Huh? My output was A B C.......
Then you must have tested it with my extension method ...
There is also an Extension method on IEnumerable(T) that is called Reverse()
s.Reverse() returns an Enumerator in reverse order - ie does not touch the stack - see
http://msdn.microsoft.com/en-us/library/bb358497.aspxStack and Queue do not implement a Reverse() whereas List(T) has both a 'natural' Reverse() method and an extension method Reverse()
Fun !
Gregory