using System; using System.Collections; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] array = { "a.m.", "a", "Smith", "Jones", "module", "zoology", "youth", "Hsieh", "abdomen", "Xerox", "season", "Luncheon", "transferable","macro","genuine" }; //var array = from a in names orderby a ascending select a;//升序 //var array = from a in names orderby a descending select a;//降序 var array = from a in array orderby Guid.NewGuid() select a; //打乱顺序序,每次运行结果都不一样 foreach (var item in array ) { Console.WriteLine(item); } Console.ReadKey(); } } }
升序排序
ascending 默认不指名就是ascending 升序
降序排序
descending 降序
//Linq var array = from a in names orderby a descending select a;//降序
乱序排序
每次运行结果都不一样,
//Linq var array = from a in array orderby Guid.NewGuid() select a; //打乱顺序序,每次运行结果都不一样
原文地址:https://www.cnblogs.com/xe2011/p/12172934.html
时间: 2024-10-07 10:01:28