W
Water Cooler v2
I can't believe I've stumbled on a simple problem such as this. After
all these years, that too.
Anyway, it goes that I just realized that I could not iterate through
my hashtable and print out its contents. On further probing, I realized
that the hashtable didn't implenent IList, which really has the
this[int] indexer. And so I couldnt do this:
for (int i = 0; i < _myHashTable.Count; i++)
Console.WriteLine(_myHashTable.ToString());
I had to know the key to index the hashtable elements. I could
enumerate through it by getting its enumerator
(IEnumerable.GetEnumerator) and then calling Next() and Current on its
IEnumerator but even then, I'd have to know the keys.
I took the hashtable in the first place because of its Contains method.
It can easily reference its elements and check for the existence of a
key, in constant time whereas list takes linear time.
Now, I am stuck. All I need to do is print out the contents of the
hashtable. The other option I can consider is to take a Dictionary or a
NameValueCollection or to take an ArrayList and extend it to have a
Contains look up method.
all these years, that too.
Anyway, it goes that I just realized that I could not iterate through
my hashtable and print out its contents. On further probing, I realized
that the hashtable didn't implenent IList, which really has the
this[int] indexer. And so I couldnt do this:
for (int i = 0; i < _myHashTable.Count; i++)
Console.WriteLine(_myHashTable.ToString());
I had to know the key to index the hashtable elements. I could
enumerate through it by getting its enumerator
(IEnumerable.GetEnumerator) and then calling Next() and Current on its
IEnumerator but even then, I'd have to know the keys.
I took the hashtable in the first place because of its Contains method.
It can easily reference its elements and check for the existence of a
key, in constant time whereas list takes linear time.
Now, I am stuck. All I need to do is print out the contents of the
hashtable. The other option I can consider is to take a Dictionary or a
NameValueCollection or to take an ArrayList and extend it to have a
Contains look up method.