public int[,] coordinate { get; set; }
フィールドを含むShape
というオブジェクトがあります。C#のIComparable
私は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'
したがって、現時点ではintを返すように戻り値を返すようにするにはどうすればよいですか?
UPDATE
私はリターン・コードを変更する場合:
return this.coordinate.CompareTo(other.coordinate);
私は、次のようなエラーメッセージを指定を取得します:実行するための
Error 1 'ShapeD.Game_Objects.Shape' does not implement interface member 'System.IComparable.CompareTo(ShapeD.Game_Objects.Shape)'. 'ShapeD.Game_Objects.Shape.CompareTo(ShapeD.Game_Objects.Shape)' cannot implement 'System.IComparable.CompareTo(ShapeD.Game_Objects.Shape)' because it does not have the matching return type of 'int'. C:\Users\Usmaan\Documents\Visual Studio 2012\Projects\ShapeD\ShapeD\ShapeD\Game Objects\Shape.cs 10 18 ShapeD
新しいエラーメッセージはかなりです単純に解決する** public int CompareTo(Shape other)** to ** public int CompareTo(オブジェクトother)**しかし、あなたはキャストの問題に直面し、CompareToは複数次元の配列に対しては存在しません。 –