Feramuz Alaçal

Feramuz Alaçal

  • NA
  • 2
  • 3.2k

2d string Array have 3 column many rows Sorting help c#

Jan 28 2018 5:52 AM
Hi I am beginner and I want to know sorting  2d string array with 3 columns.
It is rectangular array that is not a jagged array.
 
I want to sort for workedYear column. 
 example array
  string[,] workedYear_Name_Stat = { {"8", "ab","married" },
                                                            { "2", "ca","married"},
                                                            { "1", "ga","single" },
                                                            { "3", "as","married" }};
 
if it was like   string[,] workedYearName = { {"8", "ab" },
                                                                 { "2", "ca"},
                                                                 { "1", "ga" },
                                                                 { "3", "as"}};
Below code sorts workedYearName because it has 2 columns.
  private static void Sirala(string[,] dizi) 
      {
                              int length = dizi.Length / dizi.Rank;

                              for (int i = 0; i < length - 1; i++)
                              {
                                    for (int j = i + 1; j < length; j++)
                                       {
                                                int ilk = int.Parse(dizi[i, 0]);
                                                int ikinci = int.Parse(dizi[j, 0]);

                                                if (ilk > ikinci)
                                                {
                                                   string temp0 = dizi[i, 0];
                                                      string temp1 = dizi[i, 1];

                                                         dizi[i, 0] = dizi[j, 0];
                                                            dizi[i, 1] = dizi[j, 1];
                                                            dizi[j, 0] = temp0;
                                                         dizi[j, 1] = temp1;
                                                   }
                                       }
                              }
            }

Answers (1)