I encountered a sorting requirement at work today.
My first reaction was to use Linq, which indeed meets the requirement, but when I was writing it, I always felt that I had forgotten something.
List xxlist = (from a in yyList orderby a.num descending select a).ToList();
When I went back to check the code later, I felt like I remembered that there was a ready-made syntax. I hadn’t used it for a long time and had forgotten the syntax. I’ll record it here.
//This is how num is sorted from small to large
xxList.Sort((x, y) =>
{ return x.num.CompareTo(y.num); });
If you are just sorting, you can directly use
xxList.Sort();
Record it so you don’t forget it later