[Gambas-user] Sort an array of Objects[] of different Class

Jussi Lahtinen jussi.lahtinen at gmail.com
Tue Apr 21 23:46:17 CEST 2020


Hmm... no, here is the preferred method.


Jussi

On Wed, Apr 22, 2020 at 12:39 AM Jussi Lahtinen <jussi.lahtinen at gmail.com>
wrote:

> Interesting problem.
> I suggest you make the object inherit the same class, which is base for
> the comparison, but if you cannot do that, then you need to implement the
> same things in every class. See attachment for that.
>
>
> Jussi
>
> On Tue, Apr 21, 2020 at 11:27 PM martin p cristia <tercoide at hotmail.com>
> wrote:
>
>> It is posible to use the .Sort() method to sort an array of differnt
>> Class of Objects based on a variable or property?
>>
>> dim myDifObj as New Object[]
>>
>> dim thing1 as New Class1(4) ' The class saves that number for sorting
>>
>> myDifObj.Add(thing1)
>>
>> dim thing2 as New OtherClass(3) ' The class saves that number for sorting
>>
>> myDifObj.Add(thing2)
>>
>> dim thing3 as New anOtherClass(5) ' The class saves that number for
>> sorting
>>
>> myDifObj.Add(thing3)
>>
>>
>> myDifObj.Sort()  ???
>>
>>
>> I can't figure how to use special method _Compare( ???)  if it's even
>> possible.
>>
>> Thank you.
>>
>>
>>
>> --
>> Saludos
>>
>> Ing. Martin P Cristia
>>
>>
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200422/e98d5fc3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SortObjects-2.tar.gz
Type: application/gzip
Size: 11871 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200422/e98d5fc3/attachment.gz>


More information about the User mailing list