C# Ordered dictionary index
- by Martijn
I am considering of using the OrderedDictionary. As a key I want to use a long value (id) and the value will be a custom object.
I use the OrderedDictionary because I want to get an object by it's Id and I want to get an object by it's 'collection' index.
I want to use the OrderedDictionary like this:
public void AddObject(MyObject obj)
{
_dict.Add(obj.Id, obj); // dict is declared as OrderedDictionary _dict = new OrderedDictionary();
}
Somewhere else in my code I have something similar like this:
public MyObject GetNextObject()
{
/* In my code keep track of the current index */
_currentIndex++;
// check _currentindex doesn't exceed the _questions bounds
return _dict[_currentIndex] as MyObject;
}
Now my question is. In the last method I've used an index. Imagine _currentIndex is set to 10, but I have also an object with an id of 10. I've set the Id as a key.
The Id of MyObject is of type long?. Does this goes wrong?