下面这个函数 参数imformations 是一个以格式 如  520-lks-88 的字符串组成的一维数组,
格式对应的是  学号-姓名-分数  ,将一维数组分离然后组成二维数组,paixuById[x,y] 其中X就是一维数组imformations的
长度,y 是 字符串飞离出来的长度也就是3,请高手帮忙排下序,实现在 二维数组中将 学号从大到小,或者从小到大排列,
然后将一维数组以学号大小的顺序打印出来,话有点多!!        static void outputbyId(string[] imformations)
        {
            string[,] paixuByid = new string[imformations.Length, 3];
            for (int i = 0; i < imformations;i++)
            {
                string[] imfma = imformations[i].Split('-');
                paixuByid[i, 0] = imfma[0];
                paixuByid[i, 1] = imfma[1];
                paixuByid[i, 2] = imfma[2];
            }
            for (int i = 0; i < paixuByid.Length / 3; )
            {
                int min = i;
                for (int j = i + 1; j < paixuByid.Length / 3;j++ )
                {   
                    int temp;
                    if(int.Parse (paixuByid[j,0])<int.Parse (paixuByid [min,0]) )
                            
                }
            }        }

解决方案 »

  1.   


            static void outputbyId(string[] imformations)
            {
                Array.Sort(imformations, (x, y) =>
                    {
                        var i=int.Parse(x.Substring(0,x.IndexOf("-")));
                        var j=int.Parse(y.Substring(0,x.IndexOf("-")));
                        if(i>j) 
                            return 1;
                        else if(i<j)
                            return -1;
                        else
                            return 0;
                               
                    });
                //排好序的一维数组
                foreach (var t in imformations)
                {
                    Console.WriteLine(t);            }            string[,] paixuByid = new string[imformations.Length, 3];
                for (int i = 0; i < imformations.Length; i++)
                {
                    string[] imfma = imformations[i].Split('-');
                    paixuByid[i, 0] = imfma[0];
                    paixuByid[i, 1] = imfma[1];
                    paixuByid[i, 2] = imfma[2];
                }
                //输出二维数组
                for (int i = 0; i < paixuByid.GetUpperBound(0); i++)
                {
                    Console.WriteLine(paixuByid[i, 0]);
                }
            }
      

  2.   

    貌似这是选择排序法,应该这样补充
     static void outputbyId(string[] imformations) 
            { 
                string[,] paixuByid = new string[imformations.Length, 3]; 
                for (int i = 0; i < imformations;i++) 
                { 
                    string[] imfma = imformations[i].Split('-'); 
                    paixuByid[i, 0] = imfma[0]; 
                    paixuByid[i, 1] = imfma[1]; 
                    paixuByid[i, 2] = imfma[2]; 
                } 
                for (int i = 0; i < paixuByid.Length / 3; ) 
                { 
                    int min = i; 
                    for (int j = i + 1; j < paixuByid.Length / 3;j++ ) 
                    {  
                        Object temp; 
                        if(int.Parse (paixuByid[j,0]) <int.Parse (paixuByid [min,0]) ) 
                            min=j;
                        temp=paixuByid[j,0];
                        paixuByid[j,0]=paixuByid [min,0];
                        paixuByid [min,0]=temp;
                    } 
                }         }
      

  3.   

    貌似一个Array.Sort就搞定了
    还是说必须要按照要求先分成二维排序再输出?
      

  4.   

    up,自己把下面这个代码改改应该就可以用了list.Sort(new MyCompare());        private class MyCompare : System.Collections.IComparer//sort
            {
                public int Compare(object x, object y)
                {
                    string s1 = (string)x;
                    string s2 = (string)y;//下面的排序规则自己写吧
                    int year1 = int.Parse(s1.Substring(0, s1.IndexOf("年")));/
                    int year2 = int.Parse(s2.Substring(0, s2.IndexOf("年")));
                    int m1 = int.Parse(s1.Substring(s1.IndexOf("年") + 1, 2));
                    int m2 = int.Parse(s2.Substring(s2.IndexOf("年") + 1, 2));
                    int i =  (year1-year2)*12+m1-m2;
                    return -i;
                }
            }
      

  5.   


    最简单就这样了: string[] informations = new string[3];
    informations[0]= "587-lks-88";
    informations[1]= "512-jku-98";
    informations[2]= "556-art-65";
    Array.Sort(informations);
    foreach(string s in informations)
    Console.WriteLine(s);
      

  6.   

    Array.Sort 我还没学到,如果是按学号来排该怎么改呢?