我有一个名为的对象Shape
,其中包含一个public int[,] coordinate { get; set; }
字段。
我有一个单独的类,其中包含一组Shape
对象。在某个特定点上,我希望检查:
if(shapes.Contains(shape))
{
// DoSomething
}
所以在Shape
类中我添加了IComparable
引用并插入了CompareTo
方法:
public int CompareTo(Shape other)
{
return this.coordinate.Equals(other.coordinate);
}
但是,我收到一个错误:
Cannot implicitly convert type 'bool' to 'int'
因此,我该如何表述 return 以便它返回一个 int 而不是 bool,因为它目前正在这样做?
更新
如果我将返回码更改为:
return this.coordinate.CompareTo(other.coordinate);
我收到以下错误消息:
错误 1“ShapeD.Game_Objects.Shape”未实现接口成员“System.IComparable.CompareTo(ShapeD.Game_Objects.Shape)”。“ShapeD.Game_Objects.Shape.CompareTo(ShapeD.Game_Objects.Shape)”无法实现“System.IComparable.CompareTo(ShapeD.Game_Objects.Shape)”,因为它没有匹配的返回类型“int”。C:\Users\Usmaan\Documents\Visual Studio 2012\Projects\ShapeD\ShapeD\ShapeD\Game Objects\Shape.cs 10 18 ShapeD