Using lists I use
List<int> list = new List<int>();
list.AddRange(otherList);
How to do this using a Queue?, this Collection does not have a AddRange Method.
Queue<int> q = new Queue<int>();
q.AddRange(otherList); //does not exists
Using lists I use
List<int> list = new List<int>();
list.AddRange(otherList);
How to do this using a Queue?, this Collection does not have a AddRange Method.
Queue<int> q = new Queue<int>();
q.AddRange(otherList); //does not exists
otherList.ForEach(o => q.Enqueue(o));
You can also use this extension method:
public static void AddRange<T>(this Queue<T> queue, IEnumerable<T> enu) {
foreach (T obj in enu)
queue.Enqueue(obj);
}
Queue<int> q = new Queue<int>();
q.AddRange(otherList); //Work!
Queue
has a constructor that takes in an ICollection
. You can pass your list into the queue to initialize it with the same elements:
var queue = new Queue<T>(list);
in your case use as follows
Queue<int> ques = new Queue<int>(otherList);
You can initialize the queue list:
Queue<int> q = new Queue<int>(otherList);