winforms - C# Ordered dictionary index -


I am considering using OrderedDictionary. As a key, I want to use a long value (id) and the value will be a custom object.

I am using the Ordered dividend because I want to get an object through ID and I want to get the object from its 'Archive' index.

I want to use ordered files like this:

  Public Zero AddObject (MyObject obj) {_dict.Add (obj.Id, obj); // dict has been ordered as ordered _dict = new OrderedDictionary (); }  

Somewhere else in my code I have something similar:

  Public MyObject GetNextObject () {/ * Keep track of current in my code index * / _currentIndex ++; // Czech _currentindex, _questions Bound return _dict [_currentIndex] is not as much as MyObject; }  

Now my question is that in the last method I have used an index. Imagine _currentIndex is set to 10, but I also have an object with an ID of 10. I have set the ID as the key.

Is my object ID long ?. Is this wrong?

As I never saw OrderedDictionary part! The overdried near the indexer is either the object , which will be derived from the value, or int which will receive the value by the index. If you want to retrieve it with your key then you have to put your index in the form of an object, eg.

  _dict [[Object] _currentIndex] as MyObject;  

Comments