按照词典顺序对 C# 中的单词进行排序
首先,设置一个字符串数组 -
string[] arr = new string[] { "Indian", "Moroccon", "American", };
按词典顺序对单词进行排序 -
var sort = from a in arr orderby a select a;
示例
让我们查看完整的代码 -
using System; using System.Linq; class Program { static void Main() { string[] arr = new string[] { "Indian", "Moroccon", "American", }; var sort = from a in arr orderby a select a; foreach(string res in sort) { Console.WriteLine(res); } } }
输出
American Indian Moroccon
广告