Code Block Test
四个空格
hello?
help?
代码段直接粘贴
public static partial class ArrayExtension
{
public static TItem[] SortBy<TItem, TKey>(this TItem[] array, Func<TItem, TKey> sortKeySelector)
{
if (array == null) {
throw new ArgumentNullException(nameof(array));
}
if (sortKeySelector == null) {
throw new ArgumentNullException(nameof(sortKeySelector));
}
return SortBy(array, sortKeySelector, Comparer<TKey>.Default);
}
public static TItem[] SortBy<TItem, TKey>(this TItem[] array, Func<TItem, TKey> sortKeySelector, IComparer<TKey> comparer)
{
if (array == null) {
throw new ArgumentNullException(nameof(array));
}
if (sortKeySelector == null) {
throw new ArgumentNullException(nameof(sortKeySelector));
}
if (comparer == null) {
throw new ArgumentNullException(nameof(comparer));
}
if (array.Length == 0) {
return array;
}
TKey[] keys = new TKey[array.Length];
for (int i = 0; i < array.Length; i++) {
keys[i] = sortKeySelector(array[i]);
}
Array.Sort<TKey, TItem>(keys, array, comparer);
return array;
}
}
看起来还可以。虽然在这里讨论代码有些浮云。