C# 复杂对象比较
public class SecurityMaster : EntityObject
{
public string BondIdentifier { get; set; }
public string Description { get; set; }
public EntityCollection<SecurityMasterSchedules> SecurityMasterSchedules { get; set}
}
public class SecurityMasterSchedules :EntityObject
{
public string BondIdentifier { get; set; }
public decimal rate { get; set; }
public datetime startdate { get; set; }
public datetime endate { get; set; }
}
如何比较对象列表list1和列表list2? IEnumerable except 方法不适用于复杂对象。
List<SecurityMaster> list1 = new List<SecurityMaster>();
List<SecurityMaster> list2 = new List<SecurityMaster>();
public class SecurityMaster : EntityObject
{
public string BondIdentifier { get; set; }
public string Description { get; set; }
public EntityCollection<SecurityMasterSchedules> SecurityMasterSchedules { get; set}
}
public class SecurityMasterSchedules :EntityObject
{
public string BondIdentifier { get; set; }
public decimal rate { get; set; }
public datetime startdate { get; set; }
public datetime endate { get; set; }
}
How do I compare the objects List list1 and List list2? IEnumerable except method doesn't work with complex objects.
List<SecurityMaster> list1 = new List<SecurityMaster>();
List<SecurityMaster> list2 = new List<SecurityMaster>();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜您有两个
IEnumerable
序列,并且您想知道如何使用Except
将两个EntityObjects
视为在特定标准下相同。我将进一步猜测这些标准包含一个简单的规则(只是为了让我自己在提供这个答案时更轻松):具有相同BondIdentifier
属性的两个项目将被视为相同。好吧,那么,使用接受
IEqualityComparer
的Except
重载:即使我对标准的猜测是错误的,您仍然可以使用这个答案作为以此为基础来制定自己的。
如果我最初的猜测也是错误的,那么显然这个答案对你来说毫无用处。
I'm guessing you have two
IEnumerable<EntityObject>
sequences and you want to know how to useExcept
in a way that treats twoEntityObjects
as identical under specific criteria. I'm going to further guess that these criteria comprise one simple rule (just to make life easier for myself in providing this answer): two items with the sameBondIdentifier
property will be considered identical.Well, then, use the overload for
Except
that accepts anIEqualityComparer<T>
:Even if my guess as to the criteria was wrong, you can still use this answer as a basis from which to formulate your own.
If my initial guess was also wrong, then clearly this answer is useless to you.
我不确定您的代码与什么有关,但这是您使用 例外:
I'm not sure what your code has to do with anything, but here's how you use Except: