我有以下课程:
public class DocumentCompare
{
public string Customer;
public string Filename;
public string Reference;
public DateTime? Date;
public override bool Equals(object obj)
{
if (obj == null)
return false;
DocumentCompare doc = obj as DocumentCompare;
if ((Object)doc == null)
return false;
return (doc.Customer == Customer) && (doc.Date == Date) && (doc.Filename == Filename) && (doc.Reference == Reference);
}
public bool Equals(DocumentCompare doc)
{
if ((object)doc == null)
return false;
return (doc.Customer == Customer) && (doc.Date == Date) && (doc.Filename == Filename) && (doc.Reference == Reference);
}
public override int GetHashCode()
{
return string.Format("{0}_{1}_{2}_{3}",Customer,Filename,Reference,(Date == null ? "" : Date.Value.ToString())).GetHashCode();
}
}
Run Code Online (Sandbox Code Playgroud)
我将检索这个类的2个列表 - 我想要做的是比较两个,并得到两个都不存在的列表.因此,如果项目存在于x列表中但不存在于y中,我想对此列表中的项目执行操作.如果项目存在于y列表中而不存在于x中,我想要执行不同的操作.
我该怎么做?使用LINQ我猜!
编辑:性能不是一个问题 - 这只会运行一次
听起来你只是想要Except:
foreach (var newItem in firstList.Except(secondList))
{
...
}
Run Code Online (Sandbox Code Playgroud)
作为旁白:
Equals(object)到Equals(DocumentCompare),以避免重复的逻辑| 归档时间: |
|
| 查看次数: |
1390 次 |
| 最近记录: |