를 변환 할 수 없습니다 : (일반 목록과에서 IComparable 정렬 오류 : 나는 같은 내 자신의 GenericList 및 작업 클래스를 구현 한 람다 식을
public GenericList<T> where T: Task
{
public List<T> list = new List<T>();
....
public void Sort()
{
list = list.Sort((a,b) => b.Id.CompareTo(a.Id) > 0);
//here I am getting the Error Warning by Visual Studio IDE
//Error: Can not convert lambda expression to
//'System.Collections.Generic.IComparer<T>' because it is not a delegate type
}
}
public class Task
{
public int Id {get; set;}
public Task(int ID)
{Id = ID;}
}
here I am getting the Error Warning by Visual Studio IDE Error: Can not convert lambda expression to 'System.Collections.Generic.IComparer' because it is not a delegate type
나는 심지어 정렬 대신 다음 구현하기 위해 노력했다) 방법을 사용하여 Compare.Create :
list = list.OrderBy(x => x.Id,
Comparer<Task>.Create((x, y) => x.Id > y.Id ? 1 : x.Id < y.Id ? -1 : 0));
//Here the Error: the type argument for the method can not be inferred
하지만 여전히 오류가 발생합니다.
Sort를 GenericList 내에서 구현할 때 Id를 기반으로 작업을 정렬하려고합니다. 누군가가 어떻게이 일을 성취 할 수 있을까요?
도움을 주시면 감사하겠습니다. 미리 감사드립니다.
도움 주셔서 감사합니다. 그것은 완벽하게 작동했습니다. –