msdn is telling me that a generic Stack has a Clone method, and it’s “Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0” versions of .NET
Im using Unity version 3.2.0f4
On compilation, I get the error "Type System.Collections.Generic.Stack<PathNode>' does not contain a definition for Clone’ and no extension method `Clone’ of type ". So what am I doing wrong?
Oh I’ve tried that. Only problem is that since the copy constructor is inherited from the IEnumerable and the enumerator reads the elements in the same order as if they were popped from the stack which results in a reversed copy of the original.
I absolutely need it to make a exact copy of the other stack, with the elements in the same order
EDIT: Yeah, this is pretty weird. Stack for me (.NET 4.0 for Silverlight and ASP.NET) also does not have the clone method despite the MSDN stating otherwise.
EDITx2: OOOOOOoooooh
System.Collections.Generic.Stack doesn’t have the Clone method because it doesn’t implement ICloneable, but the System.Collections.Stack (non-generic) does because it implemetns ICloneable.
(I’m guessing this is due to legitimate implications of using generics where they can’t guarantee proper transfer of entries for indeterminate types?)
Anyway, the method I posted (as silly as it is) should work. Hopefully your stack is relatively small 'cause it’ll be a O(2n) operation. (which isn’t THAT bad…)
The Reverse method is an extension method provided by Linq. So if you put a “using System.Linq;” at the top of your code file, I think it might work. (I haven’t tried using extension methods or Linq in Unity, so I’m not sure)