C
Chris Skaryd
Everything I find about IDictionaryEnumerator says that they are readonly.
I'm somewhat confused by the following example. The MsgBox 4 lines from the
bottom will never be run. In the first While loop the Clear is called, but
the value is never added back into the ht object. So why is the hashtable
cleared when I get the to While m block? Shouldn't this not happen since the
Enumerator is readonly?
Thanks in advance for any explanation.
---
Dim ht As New Hashtable()
Dim I As Integer
For I = 1 To 5
Dim h As New Hashtable()
h.Add(I, I)
ht.Add(I, h)
Next I
Dim en As IDictionaryEnumerator = ht.GetEnumerator()
While en.MoveNext
en.Value.clear()
End While
Dim ne As IDictionaryEnumerator = ht.GetEnumerator()
While ne.MoveNext
Dim m As IDictionaryEnumerator = ne.Value.GetEnumerator()
While m.MoveNext
MsgBox(m.Key & "," & m.Value)
End While
End While
End Sub
I'm somewhat confused by the following example. The MsgBox 4 lines from the
bottom will never be run. In the first While loop the Clear is called, but
the value is never added back into the ht object. So why is the hashtable
cleared when I get the to While m block? Shouldn't this not happen since the
Enumerator is readonly?
Thanks in advance for any explanation.
---
Dim ht As New Hashtable()
Dim I As Integer
For I = 1 To 5
Dim h As New Hashtable()
h.Add(I, I)
ht.Add(I, h)
Next I
Dim en As IDictionaryEnumerator = ht.GetEnumerator()
While en.MoveNext
en.Value.clear()
End While
Dim ne As IDictionaryEnumerator = ht.GetEnumerator()
While ne.MoveNext
Dim m As IDictionaryEnumerator = ne.Value.GetEnumerator()
While m.MoveNext
MsgBox(m.Key & "," & m.Value)
End While
End While
End Sub