Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stack has a reverse method - which does not seem to work
Message
De
25/07/2009 13:53:55
 
 
À
25/07/2009 12:18:40
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01407785
Message ID:
01414495
Vues:
29
>>>>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>'
!
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform