public static class LinqExtension
	{
		public static T MaxBy<T, TR>(this IEnumerable<T> en, Func<T, TR> evaluate) where TR : IComparable<TR>
		{
			return en.Select(t => new Tuple<T, TR>(t, evaluate(t)))
				.Aggregate((max, next) => next.Item2.CompareTo(max.Item2) > 0 ? next : max).Item1;
		}

		public static T MinBy<T, TR>(this IEnumerable<T> en, Func<T, TR> evaluate) where TR : IComparable<TR>
		{
			return en.Select(t => new Tuple<T, TR>(t, evaluate(t)))
				.Aggregate((max, next) => next.Item2.CompareTo(max.Item2) < 0 ? next : max).Item1;
		}

	}

  

相关文章:

  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
  • 2021-12-28
  • 2021-08-17
  • 2021-07-24
猜你喜欢
  • 2022-01-25
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2022-12-23
相关资源
相似解决方案