例如  排序前输出:while if for break switch排序后输出:break for if switch while
给个思路,

解决方案 »

  1.   

    SortedList mySortedList = new SortedList();
    //while if for break switch
    mySortedList["while"] = "while";
    mySortedList["if"] = "if";
    mySortedList["for"] = "for";
    mySortedList["break"] = "break";
    mySortedList["switch"] = "switch";
    if (!IsPostBack)
    {
    string s=string.Empty;
    foreach (DictionaryEntry Item in mySortedList)
    {
    s += Item.Value.ToString()+" ";
    }
    Response.Write(s);
    }
    输出:break for if switch while  
      

  2.   

    楼上的方法可行,但是while if for break switch你怎么取得酶一个单词呢??
      

  3.   

    我记得List.Sort()默认就是以首字母排序的
    你可以试一试
      

  4.   

    告诉你个简单的方法:List<string> liststring=new List<string>
    {
    while, if, for, break ,switch
       
    };
    //用匿名方法进行排序,也可以用lambda表达式,
    liststring.sort( delegate(string str1,string str2)
       {return str1.CompareTo(str2)}
    );
      

  5.   

    贴出来看看,其实和上面差不多List<string> str = new List<string>();
                str.Add("while");
                str.Add("if");
                str.Add("for");
                str.Add("break");
                str.Add("switch");
                str.Sort();
                string strsort = "";
                foreach (string s in str)
                {
                    strsort += s.ToString() + " ";
                }
                MessageBox.Show(strsort);
      

  6.   

        class Program
        {
            static void Main(string[] args)
            {
                var s = "while if for break switch";
                var res = s.Split(' ').OrderBy(x => x[0]);
                Console.WriteLine(String.Join(" ", res));
            }
        }
      

  7.   

        class Program
        {
            static void Main(string[] args)
            {
                var s = "while if for break switch";
                var res = s.Split(' ').OrderBy(x => x[0]);
                Console.WriteLine(String.Join(" ", res));
            }
        }
      

  8.   


    你需要添加一个命名空间 如下
    using System.Collections.Generic;
      

  9.   

    这是泛型,需要添加这个命名空间:
    using System.Collections.Generic;
      

  10.   

    using system.collections 这是一个命名空间,里面有像ArrayList的这样数组,集合。想用数组或者集合,就必须添加这个命名空间。随着.net 2.0(vs2005)的发表,又多了一个命名空间,system.collections.generic 这个命名空间里有一些泛型类,譬如List<T>.....