0
LINQ 라이브러리의 스타일로 사용자 지정 IComparer에 과부하가있는 클래스를 구현하고 있습니다. (예 : OrderBy : OrderBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>)
및 OrderBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, IComparer<TKey>)
).T가 IComparable <T>을 구현하는 곳에서 LINQ 유형 IComparer <T> 오버로드를 구현하려면 어떻게해야합니까?
1 인수 오버로드의 관점에서 2 인수 오버로드를 구현하고 싶습니다. 다음과 같은 뭔가 :이 점에서
T Method<T>(IEnumerable<T> collection, IComparer<T> comparer)
{
// Do something that returns a T
}
T Method<T>(IEnumerable<T> collection) where T: IComparable<T>
{
IComparer<T> comparer = /*what goes here?*/;
return Method(collection, comparer);
}
는 질문은, 어떻게하여 IComparable을 구현하는 유형 IComparer의 인스턴스를 얻을 수 있습니까 요구로 귀결?