Title: How to check a list (Of T) if it contains an item, but ignoring if one property is different?
Tags: vb.net;contains
Question: So I have a struct that is called alarm, and a list of alarms called alarmList. I go through a loop to see if there are any new alarms. If the List of alarms already has it, I say ignore it and continue:
Dim alarms() = G4TAPIs.G4TGetActivity(MyActRequest)  'get updated list of alarms
'this list may include all of the alarms previously.
For Each alarm In alarms
'if acknowledged, don't show
If alarm.AckedFlag = True And alarm.ResetFlag = True Then
Continue For
End If
If alarmList.Contains(alarm) Then
Continue For
End If
'do stuff to process
alarmList.add(alarm)  'add new alarm
What happens is this guy in called regularly. Alarms() is updated with ALL past alarms, including the ones I already processed, but it updates their time to the current time, despite them already having happened. So i check to see if they're already processed on my list with contains.
Is there a way (linq methods are welcomed as well!) to edit the contains condition so that it ignores one feature if it is different? Particularly alarm.when (a Date type variable). It updates to the current date, and I want to make sure that the contains list checks to see if they're equal in all instances BUT the .when.
What's the best way to do this?
Comment: Are you willing to override the default equality comparator?

Comment: The [`IEnumerable.Any`](http://msdn.microsoft.com/en-us/library/vstudio/bb534972%28v=vs.100%29.aspx) method can take a predicate that can do any comparison you want.

Comment: (shrug) Sure. Just curious to see what options are out there.


Here is another answer: Create an IEqualityComparer that ignores the property you don't want to check, and use the overloaded Contains that accepts the value and an IEqualityComparer.
Sorry - this is c#, not VB... I rarely write VB, and if I tried - it would likely be very ugly.
class AlarmEqualityComparer : IEqualityComparer<Alarm&gt;
public bool Equals(Alarm a1, Alarm a2)
// check whatever properties you want
public int GetHashCode(Alarm a1)
// build a hashcode using the properties that are checked
Edit... VB translation added.
Class AlarmEqualityComparer
Implements IEqualityComparer(Of Alarm)
Public Function Equals(a1 As Alarm, a2 As Alarm) As Boolean
' Check whatever properties you want
End Function
Public Function GetHashCode(a1 As Alarm) As Integer
' Build a hashcode using the properties that are checked
End Function
End Class
Comment for this answer: No worries! I get the concept.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:08/08/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<vb.net><contains>', 'Title': 'How to check a list (Of T) if it contains an item, but ignoring if one property is different?', 'ViewCount': 110, 'id': 25210984, 'user_AboutMe': '', 'user_AccountId': 3821774.0, 'user_DisplayName': 'Kat', 'user_Reputation': 2420.0, 'user_Views': 296.0, 'user_id': 3169706.0}}