[Gambas-user] Accessing the nth item in a collection

Jussi Lahtinen jussi.lahtinen at ...626...
Wed Jun 4 02:46:08 CEST 2014


If I remember correctly Benoit warned that collections doesn't necessarily
keep the items in order. But I don't know what would make it to lose the
order. Maybe he will enlighten the issue.
Anyway I suggest you use array of objects, which you declare extra property
"Key".


Jussi


On Wed, Jun 4, 2014 at 3:22 AM, B Bruen <bbruen at ...2308...> wrote:

> Occasionally, and unfortunately for me lately quite frequently, I have
> found a need to access the first or last item in (or perhaps better "the
> first or last item added to")  a collection regardless of key values (and
> by extension I could envisage a need to access the nth item in a collection
> regardless of the key value). There does not seem to be an elegant solution
> to this - or maybe just that I am incapable of developing an elegant
> solution to this.
>
> "First" can be achieved by using the For Each construct and
> unconditionally Break'ing the iteration on the first loop. This smells like
> using a sledge hammer to crush an ant.
> "Last" I have achieved after a manner, but the mechanism is too
> embarrassing to reveal.
> "nth" I am reluctant to attempt.
>
> Any clues?
>
> --
> B Bruen <bbruen at ...2308...>
>
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/NeoTech
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list