Serially assign values to OrderedDictionary c#

I have 2 key value pairs, now i want to fill up the larger one with values from the smaller one in a serial manner.

  OrderedDictionary pickersPool = new OrderedDictionary(); // small
  OrderedDictionary pickersToTicketMap = new OrderedDictionary(); // big

  pickersPool.Add("emp1", 44);   
  pickersPool.Add("emp2", 543);

Now i need to update pickersToTicketMap to to look like this

   ("100", 44);   
   ("109", 543);
   ("13", 44);   
   ("23", 543);

so basically i need the pickersPool value to cycle through the keys of pickersToTicketMap Dictionary.

i need pickerPool values to keep cycling pickersToTicketMap and updating its value serially.

Edit :

the pickersToTicketMap orderedlist initially has a value of

   ("100", "null");   
   ("109", "null");
   ("13", "null");   
   ("23", "null");

so i need for the values of PickerPool orderedDictionary to fill up those nulls in a repeated fashion.

Jon Skeet
people
quotationmark

It sounds like you should start with a List<string> (or possibly a List<int>, given that they all seem to be integers...) rather than populating your map with empty entries to start with. So something like:

List<string> tickets = new List<string> { "100", "109", "13", "23" };

Then you can populate your pickersToTicketMap as:

var pickers = pickersPool.Values;
var pickerIterator = pickers.GetEnumerator();
foreach (var ticket in tickets)
{
    if (!pickerIterator.MoveNext())
    {
        // Start the next picker...
        pickerIterator = pickers.GetEnumerator();
        if (!pickerIterator.MoveNext())
        {
            throw new InvalidOperationException("No pickers available!");
        }
    }
    ticketToPickerMap[ticket] = pickerIterator.Current;
}

Note that I've changed the name from pickersToTicketMap to ticketToPickerMap because that appears to be what you really mean - the key is the ticket, and the value is the picker.

Also note that I'm not disposing of the iterator from pickers. That's generally a bad idea, but in this case I'm assuming that the iterator returned by OrderedDictionary.Values.GetEnumerator() doesn't need disposal.

people

See more on this question at Stackoverflow