OrderedDictionaryの使用を検討しています。キーとして長い値(id)を使用したいので、値はカスタムオブジェクトになります。
OrderedDictionaryを使用するのは、そのIDでオブジェクトを取得し、その「コレクション」インデックスでオブジェクトを取得するためです。
次のようなOrderedDictionaryを使用したいと思います。
public void AddObject(MyObject obj)
{
_dict.Add(obj.Id, obj); // dict is declared as OrderedDictionary _dict = new OrderedDictionary();
}
私のコードのどこかに、次のようなものがあります。
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;
}
今私の質問はです。最後の方法では、インデックスを使用しました。_currentIndexが10に設定されていると想像してください。ただし、IDが10のオブジェクトもあります。Idをキーとして設定しました。
MyObjectのIDはlong型ですか?これはうまくいきませんか?