Collection sorting question 
Author Message
 Collection sorting question

Hello,

Is it ever possible that:

For i = 0 to MyCollection.Count -1
   MyCollection(i).tostring
Next

will sort through a collection in a different order than:

For Each MyObj in MyCollection
   MyObj.ToString
Next

Assuming that we don't insert anything into the collection
while we're looping through it.

Thanks,
Eric



Wed, 05 Oct 2005 05:07:53 GMT  
 Collection sorting question
Hello Eric,


Quote:
> Is it ever possible that:

> For i = 0 to MyCollection.Count -1
>    MyCollection(i).tostring
> Next

> will sort through a collection in a different order than:

> For Each MyObj in MyCollection
>    MyObj.ToString
> Next

This depends on the type of the collection you "loop" through the
connection. When implementing a custom collection you can provide your own
enumerator which defines the order (this can be a curtom order) of the
enumeration in a For...Each loop.

Regards,
Herfried K. Wagner



Wed, 05 Oct 2005 06:33:46 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Collection.Add and Collection.Item question?

2. Sorting Collection Objects

3. Any ideas on sorting or ordering a Collection?

4. Sorting user-defined objects - Collection vs. array

5. Sorting an items collection in C#

6. sort collection

7. Sorted collections that contain classes.

8. Using the sort method in custom collection classes

9. Impementing Sorting in Collections.

10. Sorting a collection

11. Files Collection Sort

12. How can we sort a collection?

 

 
Powered by phpBB® Forum Software