var strTest = new List<string> { "B2", "B1", "B10", "B3" };
我想如下「B1,B2,B3,B10」對它們進行排序的下面的列表。
如果我使用LINQ排序依據它按這種方式 「B1,B10,B2,B3」
請幫助。這是我的代碼。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SortingDemo
{
class Program
{
static void Main(string[] args)
{
var strTest = new List<string> { "B2", "B1", "B10", "B3" };
var sort = strTest.OrderBy(x => x);
var sortedStr = string.Join(",", sort);
Console.WriteLine(sortedStr);
Console.ReadLine();
}
也看看這裏的答案:http://stackoverflow.com/questions/248603/natural-sort-order-in-c-sharp和在這裏:http://stackoverflow.com/questions/1323550/linq和自然排序順序 –