How to get the key from a TDictionary?
I have a TDictionary<TKeyClass, TValueClass>
.
I want to accomplish something like
for i := 0 to MyDictionary.Count -1 do
ShowMessage(MyDictionary.Keys[i].AStringProperty)
I cannot Access the Keys anymore I can just use them if I exactly know them.
Is the only alternative c开发者_开发问答reate a TDictionary<TValueClass, TKeyValue>
? So I can loop thorugh the Keys?
The workaroud I found is to create a TList<TKeyClass>
but this is something i don't like.
Use an enumerator.
for Key in MyDictionary.Keys do
ShowMessage(Key.AStringProperty);
Since TDictionary is a hash table, you can't access it with integer indexing like an array or TList. But an enumerator works just fine.
精彩评论