C# IComparer未实现接口成员-错误CS0738

C# IComparer未实现接口成员-错误CS0738,c#,icomparer,C#,Icomparer,我尝试使用以下代码按两个对象的一个属性(.Transaction.topLeftX,一个整数)对它们进行排序,以创建一个比较器用于排序方法: public class RespComp : IComparer<Kairos.Net.RecognizeImage> { public Kairos.Net.RecognizeImage Compare(Kairos.Net.RecognizeImage x, Kairos.Net.RecognizeImage y

我尝试使用以下代码按两个对象的一个属性(.Transaction.topLeftX,一个整数)对它们进行排序,以创建一个比较器用于排序方法:

public class RespComp : IComparer<Kairos.Net.RecognizeImage>
{     
        public Kairos.Net.RecognizeImage Compare(Kairos.Net.RecognizeImage x, Kairos.Net.RecognizeImage y)
        {
            if (x.Transaction.topLeftX.CompareTo(y.Transaction.topLeftX) <= 0) return x;
               else return y;                      
        }
}
公共类响应:IComparer
{     
公共Kairos.Net.RecognizeImage比较(Kairos.Net.RecognizeImage x,Kairos.Net.RecognizeImage y)
{
如果(x.Transaction.topLeftX.CompareTo(y.Transaction.topLeftX),
IComparer
接口应该实现一个方法,返回一个
int
比较。
-1
表示小于,
0
表示等于,
1
表示大于

看看您的代码,如果您只是比较左上角的代码,您可能只需要执行以下操作:

public int Compare(FooImage x, FooImage y) {
    return x.Transaction.topLeftX.CompareTo(y.Transaction.topLeftX);
}

通过以下代码实现了按对象参数之一对对象进行排序的预期结果:

...
Kairos.Net.KairosClient client = new Kairos.Net.KairosClient();
client.ApplicationID = appId;
client.ApplicationKey = appKey;
Kairos.Net.RecognizeResponse resp = client.Recognize(...);

RespComp SortImages = new RespComp();
resp.Images.Sort(SortImages);
...

 public class RespComp : IComparer<Kairos.Net.RecognizeImage>
    {
        public int Compare(Kairos.Net.RecognizeImage x, Kairos.Net.RecognizeImage y)
        {
            return x.Transaction.topLeftX.CompareTo(y.Transaction.topLeftX);
        }
    }  
。。。
Kairos.Net.KairosClient=new Kairos.Net.KairosClient();
client.ApplicationID=appId;
client.ApplicationKey=appKey;
Kairos.Net.RecognizeResponse resp=client.Recognize(…);
RespComp SortImages=新RespComp();
分别图像排序(排序);
...
公共类响应:IComparer
{
公共整数比较(Kairos.Net.RecognizeImage x、Kairos.Net.RecognizeImage y)
{
返回x.Transaction.topLeftX.CompareTo(y.Transaction.topLeftX);
}
}  

您可以在界面中发布方法的签名吗?“因为它没有匹配的返回类型“int”。是的,您的方法必须返回“int”。
因为它没有匹配的返回类型“int”。
是-这是您需要做的。