Discussion:
Array.Sort(SortMethod As Delegate)
Jean-Luc Arnaud
2018-08-06 09:39:36 UTC
Permalink
Hi all,

I'd like to sort an array of FolderItems using a Sort Delegate method
based on their NativePath property.

But the Language Reference says:

"The delegate function must not mutate or examine at the contents of the
array while it is being sorted. Doing so will result in undefined behavior."

Is getting the NativePath of a FolderItem item in array considered as
examining the content of this array?

Is so, how would you sort such an array on NativePath criteria?

TIA
--
Jean-Luc Arnaud
donJ
2018-08-06 14:10:55 UTC
Permalink
Post by Jean-Luc Arnaud
Hi all,
I'd like to sort an array of FolderItems using a Sort Delegate method
based on their NativePath property.
"The delegate function must not mutate or examine at the contents of
the array while it is being sorted. Doing so will result in undefined
behavior."
Is getting the NativePath of a FolderItem item in array considered as
examining the content of this array?
Is so, how would you sort such an array on NativePath criteria?
TIA
HI Jean-Luc,
If it doesn't work, couldn't you just build a second arry of paths and
sort it using SortWith to sort the FolderItems? I sort custom classes
this way all the time.

Don
Jean-Luc Arnaud
2018-08-06 15:24:28 UTC
Permalink
Hi Don,

Thanks for replying.

I didn't test because of the "undefined behavior"!! And so, I hoped that
someone would confirm it's not recommended to do this that way.

Finally, after your reply, I tested it and it seems to work. Actually, I
h'aven't seen "undefined behavior".

Nevertheless, thank you very much for the advice, it would be very
usefull if something goes wrong...

Jean-Luc Arnaud
Post by donJ
Post by Jean-Luc Arnaud
Hi all,
I'd like to sort an array of FolderItems using a Sort Delegate method
based on their NativePath property.
"The delegate function must not mutate or examine at the contents of
the array while it is being sorted. Doing so will result in undefined
behavior."
Is getting the NativePath of a FolderItem item in array considered as
examining the content of this array?
Is so, how would you sort such an array on NativePath criteria?
TIA
HI Jean-Luc,
If it doesn't work, couldn't you just build a second arry of paths and
sort it using SortWith to sort the FolderItems? I sort custom classes
this way all the time.
Don
Loading...