D
David H
I'm implementing an application that needs to keep track of a
prioritized list of items. To do this, am using a dictonary along the
lines of :
Dictonary<int,string> myList =new Dictonary<int, string>()
The key represents the priority. The problem? I need for the
dictionary to allow me to add new items of the same priority and
simply bump down the existing item. For example:
myList.Add(1,"B");
myList.Add(2,"C");
myList.Add(3,"D");
A call to correct the list and add a (myList.Add(1,"A") will fail with
an exception.
My solution has been to wrap the dictionary in a class and create a
custom add method for the class that will re-order the dictionary.
The result is
myCustomList.Add(1,"B");
myCustomList.Add(2,"C");
myCustomList.Add(3,"D");
//No exception...The list is re-ordered and expanded so that A is now
1, and b is 2 ext..
myCustomList,Add(1,"A");
So I've solved the problem, but I can't help but wonder if I'm doing
more work than I need to. Is there a better way of handling a
situation like this?
Any suggestions/advice would be appreciated.
prioritized list of items. To do this, am using a dictonary along the
lines of :
Dictonary<int,string> myList =new Dictonary<int, string>()
The key represents the priority. The problem? I need for the
dictionary to allow me to add new items of the same priority and
simply bump down the existing item. For example:
myList.Add(1,"B");
myList.Add(2,"C");
myList.Add(3,"D");
A call to correct the list and add a (myList.Add(1,"A") will fail with
an exception.
My solution has been to wrap the dictionary in a class and create a
custom add method for the class that will re-order the dictionary.
The result is
myCustomList.Add(1,"B");
myCustomList.Add(2,"C");
myCustomList.Add(3,"D");
//No exception...The list is re-ordered and expanded so that A is now
1, and b is 2 ext..
myCustomList,Add(1,"A");
So I've solved the problem, but I can't help but wonder if I'm doing
more work than I need to. Is there a better way of handling a
situation like this?
Any suggestions/advice would be appreciated.