protected void Page_Load(object sender, EventArgs e) { string[] arr = { "bb", "bb", "fff", "a", "ffff", "c", "dd", "f", "dd", "e", "dd" }; for (int i = 0; i < arr.Length; i++) { Response.Write(arr[i]); Response.Write("<br>"); } SortByCount(arr); Response.Write("=========================="); Response.Write("<br>"); for (int j = 0; j < arr.Length; j++) { Response.Write(arr[j]); Response.Write("<br>"); } } //数组排序 public void SortByCount(string[] source) { Comparison<string> com = new Comparison<String>(function); Array.Sort<string>(source, com); } int function(string s1, string s2) { return s1.Length - s2.Length == 0 ? string.Compare(s1, s2) : s1.Length - s2.Length; }