Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I implement a Queue of type Dictionary<int, string> and iterate/enqueue/dequeue in C#

I am looking to implement a Queue of type Dictionary<int, string> and be able to iterate/enqueue/dequeue.

What's ultimately needed is a queue of int, string, whatever guise it takes.

So far I have something like:

  private static Queue<Dictionary<int, string>> requestQueue = new Queue<Dictionary<int, string>>();

  foreach (KeyValuePair<int, string> dictionaryListItem in dictionaryList)
  {
      requestQueue.Enqueue( dictionaryListItem ); // error
  }

but can't seem to enqueue with the above. Would anyone know the correct syntax?

like image 834
Gga Avatar asked Oct 24 '25 18:10

Gga


1 Answers

Well, you have a queue of dictionaries, but try to add a single dictionary value to your queue.

If you indeed want to have a queue of dictionaries, you should change your code like this:

requestQueue.Enqueue(dictionaryList);

If you actually want a queue of key value pairs, change your queue to this:

Queue<KeyValuePair<int, string>> requestQueue
like image 63
Daniel Hilgarth Avatar answered Oct 27 '25 08:10

Daniel Hilgarth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!