Reputation: 7931
var queue = new Queue<ExchangeEmailInformation>(newMails);
How can I convert the above queue to List
.
Upvotes: 3
Views: 18711
Reputation: 223277
You can use Enumerable.ToList
var list = queue.ToList();
Remember to include using System.Linq;
Upvotes: 25
Reputation: 1371
Try this... simple
System.Collections.Queue q = new System.Collections.Queue(4);
q.Enqueue("hai"); q.Enqueue("how"); q.Enqueue("are"); q.Enqueue("u");
int count = q.Count;
List<string> list = new List<string>();
for(int i =0; i < count; i++)
{
list.Add(q.Dequeue().ToString());
}
Upvotes: -1
Reputation: 217313
Since the Queue<T> Class implements IEnumerable<T> and the List<T> Class has a constructor that accepts an IEnumerable<T>, you can simply pass the queue to that constructor:
var result = new List<ExchangeEmailInformation>(queue);
Upvotes: 5