Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stack has a reverse method - which does not seem to work
Message
From
25/07/2009 13:53:55
 
 
To
25/07/2009 12:18:40
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01407785
Message ID:
01414495
Views:
31
>>>>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.aspx
>
>
>Stack and Queue do not implement a Reverse() whereas List(T) has both a 'natural' Reverse() method and an extension method Reverse()
>
>
>Fun !

doh! I thought you meant that your extension method wasn't working. I see what you mean about the inbuilt one.

var c = s.Reverse() (on the native em) shows that the return type is
'System.Linq.Enumerable.ReverseIterator<string>'
!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform