Get Item from Collection by unique ID
- by David Murdoch
I have a collection of Contacts that inherits from CollectionBase:
public class ContactCollection : CollectionBase{
//...
}
each contact in the collection has a unique ID:
public class Contact{
public int ContactID{
get;
private set;
}
//...
}
I think what I would like to do is something like the following:
// get the contact by their unique [Contact]ID
Contact myPerson = Contact.GetContactById(15);
// get all contacts for the customer
ContactCollection contacts = customer.GetContacts();
// replaces the contact in the collection with the
// myPerson contact with the same ContactID.
contacts.ReplaceAt(myPerson);
// saves the changes to the contacts and the customer
// customer.Save();
There is probably a better way...if so, please suggest it.