I have a class ‘DataSet’ whose super is ‘Collection’
When it try to use it in a for each loop i get a message that says I haven’t implemented the iterator class. Can someone show me an example of how to implement an iterator over a Collection via the interface?
for each el as element in myDataSet
...
next
This object does not implement the Iterable interface and cannot be used in a For Each loop
IIRC, Collections guarantee the order of the items won’t change while Dictionary does not. That’s not to say that they won’t be, just that it’s not guaranteed.
Now… you could subclass Dictionary to add an index to be sure that you can always get things back in the same order as they were added, but that would surely slow things down, especially when adding or removing values.
I have used Dictionary in many projects in the last 10 years and never happened to get the order shuffled using the for…each construct.
I also had this discussion with many other developers and everyone agreed on the fact it’s safe to use in this way.