StringAndDigitSort 字符串和数字组合成字符串排序

 public class CustomComparer : System.Collections.IComparer     {

        public int Compare(object x, object y)         {

            string s1 = (string)x;             string s2 = (string)y;             if (s1.Length > s2.Length) return 1;

            if (s1.Length < s2.Length) return -1;

            for (int i = 0; i < s1.Length; i++)             {

                if (s1[i] > s2[i]) return 1;

                if (s1[i] < s2[i]) return -1;

            }

            return 0;         }         public void Mains()         {             string[] str = new string[] { "A1 ", "A2 ", "A10 ", "A8 " };             string[] str2 = new string[] { @"\\r2-3\2.0.3 ", @"\\r2-3\2.0.1 ", @"\\r2-3\2.0.52 ", @"\\r2-3\2.0.34 " };             Array.Sort(str2, new CustomComparer());

            for (int i = 0; i < str2.Length; i++)                 Console.WriteLine(str2[i]);         }     }

 

Notepad:

Compare非静态方法。

posted @ 2012-06-19 00:07  qqliukk  阅读(234)  评论(1编辑  收藏  举报