static void SortImpl(Array keys, Array?items, int index, int length, IComparer comparer) { /* TODO: CoreCLR optimizes this case via an internal call * if (comparer == Comparer.Default) * { * bool r = TrySZSort(keys, items, index, index + length - 1); * if (r) * return; * }*/ object[]? objKeys = keys as object[]; object[]? objItems = null; if (objKeys != null) { objItems = items as object[]; } if (objKeys != null && (items == null || objItems != null)) { SorterObjectArray sorter = new SorterObjectArray(objKeys, objItems, comparer); sorter.Sort(index, length); } else { SorterGenericArray sorter = new SorterGenericArray(keys, items, comparer); sorter.Sort(index, length); } }
static void SortImpl(Array keys, Array items, int index, int length, IComparer comparer) { Object[] objKeys = keys as Object[]; Object[] objItems = null; if (objKeys != null) { objItems = items as Object[]; } if (objKeys != null && (items == null || objItems != null)) { SorterObjectArray sorter = new SorterObjectArray(objKeys, objItems, comparer); sorter.Sort(index, length); } else { SorterGenericArray sorter = new SorterGenericArray(keys, items, comparer); sorter.Sort(index, length); } }
// Sorts the elements in a section of two arrays based on the keys in the // first array. Elements in the keys array specify the sort keys for // corresponding elements in the items array. The sort compares the // keys to each other using the given IComparer interface. If // comparer is null, the elements are compared to each other using // the IComparable interface, which in that case must be implemented // by all elements of the given section of the keys array. // /// <include file='doc\Array.uex' path='docs/doc[@for="Array.Sort7"]/*' /> public static void Sort(Array keys, Array items, int index, int length, IComparer comparer) { if (keys==null) throw new ArgumentNullException("keys"); if (keys.Rank != 1 || (items != null && items.Rank != 1)) throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported")); if (items != null && keys.GetLowerBound(0) != items.GetLowerBound(0)) throw new ArgumentException(Environment.GetResourceString("Arg_LowerBoundsMustMatch")); if (index < keys.GetLowerBound(0) || length < 0) throw new ArgumentOutOfRangeException((length<0 ? "length" : "index"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (keys.Length - (index+keys.GetLowerBound(0)) < length || (items != null && index > items.Length - length)) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); if (length > 1) { if (comparer == Comparer.Default || comparer == null) { int r = TrySZSort(keys, items, index, index + length - 1); if (r != 0) return; } Object[] objKeys = keys as Object[]; Object[] objItems = null; if (objKeys != null) objItems = items as Object[]; if (objKeys != null && (items==null || objItems != null)) { SorterObjectArray sorter = new SorterObjectArray(objKeys, objItems, comparer); sorter.QuickSort(index, index + length - 1); } else { SorterGenericArray sorter = new SorterGenericArray(keys, items, comparer); sorter.QuickSort(index, index + length - 1); } } }