我有以下课程:
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)
);
}
}
我有两个 ICollection 集合:
ICollection<ObjectiveDetail> _obj1; // Reference
ICollection<ObjectiveDetail> _obj2; // May have more, less or different objectDetails from the reference.
集合的公共字段是ObjectiveDetailId。如何使用for 循环遍历集合以获取以下行:
- 位于 _obj2 而不是 _obj1
- 位于 _obj1 而不是 _obj2
- _obj1 和 _obj2 不同
请注意,这类似于我之前提出的另一个问题,但我认为现在我已经添加了 Equals 方法,这有点简单。