using System; using System.Collections.Generic; using System.Text; using System.Collections;namespace 字母排序 { class Program { static void Main(string[] args) { string pxq = "cadbxhjjjjhkz"; ArrayList stral = new ArrayList(); for (int i = 0; i < pxq.Length; i++) { string x = pxq.Substring(i,1); stral.Add(x); } stral.Sort(); foreach (string a in stral) { Console.Write(a); } Console.Read(); } } } 你试下这个呢 我还是比较菜的 希望对你有帮助
for(char c='z';c>='a';c--)
{
result+=c.ToString();
}
反序:zyxwvutsrqponmlkjihgfedcba
using System.Collections.Generic;
using System.Text;
using System.Collections;namespace 字母排序
{
class Program
{
static void Main(string[] args)
{
string pxq = "cadbxhjjjjhkz";
ArrayList stral = new ArrayList();
for (int i = 0; i < pxq.Length; i++)
{
string x = pxq.Substring(i,1);
stral.Add(x);
}
stral.Sort();
foreach (string a in stral)
{
Console.Write(a);
}
Console.Read();
}
}
}
你试下这个呢 我还是比较菜的 希望对你有帮助
char[] c = str.ToCharArray();
Array.Sort( c );
str = new string( c )如果要求不区分大小写的,使用泛型方法public static void Sort<T> (
T[] array,
Comparison<T> comparison
)
MSDN有例子