using System; using System.Collections.Generic; namespace SK.Framework { public static class QueueExtension { public static Queue ForEach(this Queue self, Action action) { foreach (var item in self) { action(item); } return self; } public static T[] ToArray(this Queue self) { T[] retArray = new T[self.Count]; for (int i = 0; i < self.Count; i++) { retArray[i] = self.Dequeue(); } return retArray; } public static List ToList(this Queue self) { List retList = new List(self.Count); int count = self.Count; for (int i = 0; i < count; i++) { retList.Add(self.Dequeue()); } return retList; } public static Queue Merge(this Queue self, Queue target) { int count = target.Count; for (int i = 0; i < count; i++) { self.Enqueue(target.Dequeue()); } return self; } public static Queue Copy(this Queue self) { Queue retQueue = new Queue(self.Count); foreach (var item in self) { retQueue.Enqueue(item); } return retQueue; } } }