Logo

Programming-Idioms

History of Idiom 28 > diff from v76 to v77

Edit summary for version 77 by zqwnvl:
[C#] Add missing import; use shorter demo URL

Version 76

2021-08-16, 03:09:45

Version 77

2021-08-16, 03:11:02

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
Imports
Imports
using System.Collections.Generic;
Code
System.Array.Sort(items, Comparer<Item>.Create((a, b) => 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.
Comments bubble
Sorts the array items in-place.
Doc URL
https://docs.microsoft.com/en-us/dotnet/api/system.array.sort
Doc URL
https://docs.microsoft.com/en-us/dotnet/api/system.array.sort
Demo URL
https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAIAYAEqCMAWAbgFgAoDbHAOgBkBLKAR2JNIElgBTAWwG0BdTLU5cAzpgC8mKBwDumdt36YA3lNkAKAMwBKGGpnqcu/eoBM2zAF9muSgEEwYAIYBPSgGUA9mGDqh3ET0AYU8uAAcnMA4wAB4FLgA+SiCop051dSc9ACMLcQTMJ0owzABaTGzi7W1mUgAzbw4nAGMAC0x1eMFBKEF
Demo URL
https://sharplab.io/#gist:8369fd08fd4bc2d5ad78d42f5c30190c