c# - How to eliminate duplicates from a list? -
class infocontact { private string contacts_first_namefield; private string contacts_middle_namefield; private string contacts_last_namefield; private phonenumber[] phone_numbersfield; private emailaddress[] emailfield; }
i have list<infocontact>
list contains 7000 other program. in list out of 7000, 6500 duplicates. looking way how eliminate duplicates.
a infocontact duplicate if first_name, last_name, emailaddresses, phone numbers same.
i thought of using hashset<infocontact>
, override gethashcode() of infocontact.
i curious know if best way do. if not way better way?
firstly think of extracting unique values. use distinct() linq method comparer like:
public class infocontactcomparer : iequalitycomparer<infocontact> { public bool equals(infocontact x, infocontact y) { return x.contacts_first_namefield == y.contacts_first_namefield && x.contacts_last_namefield == y.contacts_last_namefield && ... } public int gethashcode(infocontact obj) { return obj.contacts_first_namefield.gethashcode(); } }
Comments
Post a Comment