Logo

Programming-Idioms

History of Idiom 28 > diff from v73 to v74

Edit summary for version 74 by zqwnvl:
[C#] Finish incomplete implementation; add doc and demo links

Version 73

2021-08-16, 02:32:50

Version 74

2021-08-16, 02:40:14

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Variables
items,x,p
Variables
items,x,p
Code
Array.Sort(items, (a, b) => compareFunc(a.p, b.p));
Code
System.Array.Sort(items, Comparer<Item>.Create((a, b) => a.p - b.p));
Comments bubble
Sorts the array items in-place.
Doc URL
https://docs.microsoft.com/en-us/dotnet/api/system.array.sort
Demo URL
https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAIAYAEqCMAWAbgFgAoDbHAOgBkBLKAR2JNIElgBTAWwG0BdTLU5cAzpgC8mKBwDumdt36YA3lNkAKAMwBKGGpnqcu/eoBM2zAF9muSgEEwYAIYBPSgGUA9mGDqh3ET0AYU8uAAcnMA4wAB4FLgA+SiCop051dSc9ACMLcQTMJ0owzABaTGzi7W1mUgAzbw4nAGMAC0x1eMFBKEF