Jameel Moideen
Jameel Moideen

Reputation: 7931

Convert Queue To List

var queue = new Queue<ExchangeEmailInformation>(newMails);

How can I convert the above queue to List.

Upvotes: 3

Views: 18711

Answers (3)

Habib
Habib

Reputation: 223277

You can use Enumerable.ToList

var list = queue.ToList();

Remember to include using System.Linq;

Upvotes: 25

Uthistran Selvaraj
Uthistran Selvaraj

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

dtb
dtb

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

Related Questions