, - Contains:
foreach(var item in list1) {
if (list2.Contains(item) {
}
}
, BinarySearch IComparer<T>, :
class MyComparer : IComparer<YourClass> {
private MyComparer() { }
public static readonly MyComparer Instance = new MyComparer();
public int CompareTo(YourClass a, YourClass b) {
return a.SomeProperty.CompareTo(b.SomeProperty);
}
}
foreach(var item in list1) {
if (list2.BinarySearch(item, MyComparer.Instance) >= 0) {
}
}
.Net 3.5 , HashSet<T>:
var hashset = new HashSet<YourClass>(list2);
foreach(var item in list1) {
if (hashset.Contains(item) {
}
}
, .
, .