コード例 #1
0
        /// <summary>
        /// Sorts two-dimensional array using IComparer.Sort method.
        /// </summary>
        /// <param name="arr">Array to sort.</param>
        /// <param name="comparer">IComparer.Sort delegate.</param>
        private static void Sort(int[][] arr, DelegateComparer comparer)
        {
            _ = arr ?? throw new ArgumentNullException(nameof(arr), "Array should not be null.");
            _ = comparer ?? throw new ArgumentNullException(nameof(comparer), "Comparer should not be null.");

            // Classic bubble sort.
            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = 0; j < arr.Length - 1; j++)
                {
                    // Delegate invoke.
                    if (comparer.Invoke(arr[j], arr[j + 1]) > 0)
                    {
                        var temp = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j]     = temp;
                    }
                }
            }
        }
コード例 #2
0
 public int Compare(int[] x, int[] y)
 {
     return(comparer.Invoke(x, y));
 }