using System; using System.Collections.Generic; namespace SK.Framework { public static class StackExtension { public static Stack ForEach(this Stack self, Action action) { foreach (var item in self) { action(item); } return self; } public static T[] ToArray(this Stack self) { T[] retArray = new T[self.Count]; for (int i = 0; i < retArray.Length; i++) { retArray[i] = self.Pop(); } return retArray; } public static List ToList(this Stack self) { List retList = new List(self.Count); int count = self.Count; for (int i = 0; i < count; i++) { retList.Add(self.Pop()); } return retList; } } }