排序是很常用到的方法
下面示範 由小排到大
如果是要從大排到小是使用
orderby str descending
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SortMethod
{
class Program
{
static void Main(string[] args)
{
List<string> strList =
new List<string> { "1","apple","ball","ba", "2", "4","5","8", "7" };
IEnumerable<string> enumList =
from str in strList
orderby str
select str;
string orderbyString = "原始字串:";
foreach (string str in strList)
{
orderbyString += str + ",";
}
Console.WriteLine(orderbyString);
orderbyString = "排序後的字串:";
foreach (string str in enumList)
{
orderbyString += str + ",";
}
Console.WriteLine(orderbyString);
Console.ReadLine();
}
}
}