自己写的二维数据冒泡排序算法,待排序的哪一列需要为数字类型(String类型的数字也可)
#region 二维数组排序 public static string[,] ArrSort(this string[,] sourceArr, int sortIndex, string sortType) { int row = sourceArr.GetLength(0); int col = sourceArr.GetLength(1); string[] tempArr = new string[col]; if (sortType == "降序") { for (int i = row - 1; i >= 0; i--) { for (int j = 0; j <= i - 1; j++) { if (Convert.ToInt32(sourceArr[j, sortIndex]) <= Convert.ToInt32(sourceArr[j + 1, sortIndex])) { for (int k = 0; k < col; k++) { tempArr[k] = sourceArr[j, k]; sourceArr[j, k] = sourceArr[j + 1, k]; sourceArr[j + 1, k] = tempArr[k]; } } } } } else { for (int i = row - 1; i >= 0; i--) { for (int j = 0; j <= i - 1; j++) { if (Convert.ToInt32(sourceArr[j, sortIndex]) >= Convert.ToInt32(sourceArr[j + 1, sortIndex])) { for (int k = 0; k < col; k++) { tempArr[k] = sourceArr[j, k]; sourceArr[j, k] = sourceArr[j + 1, k]; sourceArr[j + 1, k] = tempArr[k]; } } } } } return sourceArr; } #endregion