E
emma_middlebrook
Hi
I know there's a SortedDictionary in C# 2.0 but I was just converting
my existing implementation of SortedHashtable (which just wraps a
Hashtable and provides an enumerator) to use iterators as an
experiment.
The old version had the usual IEnumerator stuff and, in Current,
returned:
new DictionaryEntry(_sortedKeys[_position],
_hashTable[_sortedKeys[_position]]);
_sortedKeys is an ArrayList of the sorted hashtable's keys, set up in
the constructor of the enumerator.
Can I use the following in my SortedHashtable and it will be 'expanded
out' by the compiler to a proper implementation OK?
public IEnumerator GetEnumerator()
{
ArrayList sortedKeys = new ArrayList(_hashTable.Keys);
sortedKeys.Sort();
foreach (object o in sortedKeys)
{
yield return new DictionaryEntry(o, _hashTable[o]);
}
}
Cheers
Emma
I know there's a SortedDictionary in C# 2.0 but I was just converting
my existing implementation of SortedHashtable (which just wraps a
Hashtable and provides an enumerator) to use iterators as an
experiment.
The old version had the usual IEnumerator stuff and, in Current,
returned:
new DictionaryEntry(_sortedKeys[_position],
_hashTable[_sortedKeys[_position]]);
_sortedKeys is an ArrayList of the sorted hashtable's keys, set up in
the constructor of the enumerator.
Can I use the following in my SortedHashtable and it will be 'expanded
out' by the compiler to a proper implementation OK?
public IEnumerator GetEnumerator()
{
ArrayList sortedKeys = new ArrayList(_hashTable.Keys);
sortedKeys.Sort();
foreach (object o in sortedKeys)
{
yield return new DictionaryEntry(o, _hashTable[o]);
}
}
Cheers
Emma