String[] gyoshaKbList = row["GYOSHA_KB"].ToString().Split(',');
row["GYOSHA_KB"]里面的数据为 1到14 数字.一个或多个, 不重复,怎么样把gyoshaKbList 进行下快速排序.(除了像冒泡这种循环 ,因为已经在好多循环里了..想让程序快一点.)Sort() 这个方法.好像只能给数字排序..gyoshaKbList里面用Split(',');填充进去..好像是当成字符了.在线等.
row["GYOSHA_KB"]里面的数据为 1到14 数字.一个或多个, 不重复,怎么样把gyoshaKbList 进行下快速排序.(除了像冒泡这种循环 ,因为已经在好多循环里了..想让程序快一点.)Sort() 这个方法.好像只能给数字排序..gyoshaKbList里面用Split(',');填充进去..好像是当成字符了.在线等.
{
static void Main()
{ String[] gyoshaKbList = row["GYOSHA_KB"].ToString().Split(',');
Array.Sort(gyoshaKbList, new SortClass());
}
} class SortClass : IComparer
{
public int Compare(string x, string y)
{
return int.Parse(x) > int.Parse(y)?-1:1;
} }
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int[] Marks = {70, 75, 84, 53, 46, 90, 25 };
int I = Marks.Length; Console.Write("初始排序为:70, 75, 84, 53, 46, 90, 25");
System.Threading.Thread.Sleep(2000); Array.Sort(Marks);
Console.WriteLine("");
Console.WriteLine("按照从小到大的顺序排序后为:");
System.Threading.Thread.Sleep(2000); for (int x = 0; x < I; x++)
{
Console.WriteLine(Marks[x]);
System.Threading.Thread.Sleep(1000);
}
Console.Read();
}
}
}
这里我传入的是一个匿名方法,由于你说这里面都是数字,所以,调用它本身的CompareTo方法即可实现
其第二个参数是一个实现了IComparer接口的类,自己在类里实现排序逻辑,效果跟我那个是一样的,不过当然是直接用匿名方法来得简洁