私は次のクラスを持っています:
public ObjectiveDetail()
public int ObjectiveDetailId { get; set; }
public int Number { get; set; }
public string Text { get; set; }
public override bool Equals(object obj)
{
return this.Equals(obj as ObjectiveDetail);
}
public bool Equals(ObjectiveDetail other)
{
if (other == null)
return false;
return this.Number.Equals(other.Number) &&
(
this.Text == other.Text ||
this.Text != null &&
this.Text.Equals(other.Text)
);
}
}
2 つの ICollection コレクションがあります。
ICollection<ObjectiveDetail> _obj1; // Reference
ICollection<ObjectiveDetail> _obj2; // May have more, less or different objectDetails from the reference.
コレクションの共通フィールドはObjectiveDetailIdです。for ループを使用してコレクションをトラバースし、次の行を取得するにはどうすればよいですか。
- _obj1 ではなく _obj2 にある
- _obj2 ではなく _obj1 にある
- _obj1 と _obj2 で異なる
これは以前に尋ねた別の質問に似ていますが、Equals メソッドを追加したので少し簡単になったと思います。