using System.Collections;
public static class Program
public static void Main()
string[,] weatherDataArray = new string[6, 5]
{ "3", "20", "0", "12", "cumulus" },
{ "1", "20", "0", "11", "none" },
{ "23", "15", "0", "8", "none" },
{ "4", "12", "0", "1", "cirrus" },
{ "12", "20", "0", "12", "cumulus" },
{ "9", "15", "2", "11", "none" }
var sortedWeatherData = SortData(weatherDataArray);
for (int i = 0; i < sortedWeatherData.GetLength(0); ++i)
for (int j = 0; j < sortedWeatherData.GetLength(1); ++j)
Console.Write(sortedWeatherData[i,j] + ", ");
public static string[,] SortData(string[,] data)
int[] indexer = Enumerable.Range(0, data.GetLength(0)).ToArray();
var comparer = new WeatherComparer(data);
Array.Sort(indexer, comparer);
string[,] result = new string[data.GetLength(0), data.GetLength(1)];
for (int row = 0; row < indexer.Length; ++row)
for (int col = 0; col < data.GetLength(1); ++col)
result[dest, col] = data[row, col];
public sealed class WeatherComparer: IComparer
readonly string[,] _data;
public WeatherComparer(string[,] data)
public int Compare(object? x, object? y)
double temperature1 = double.Parse(_data[row1, 1]);
double temperature2 = double.Parse(_data[row2, 1]);
if (temperature1 < temperature2)
if (temperature2 < temperature1)
int day1 = int.Parse(_data[row1,0]);
int day2 = int.Parse(_data[row2,0]);
return day1.CompareTo(day2);