【发布时间】:2010-04-27 14:57:23
【问题描述】:
我有一个继承自 CollectionBase 的联系人集合:
public class ContactCollection : CollectionBase{
//...
}
集合中的每个联系人都有一个唯一的 ID:
public class Contact{
public int ContactID{
get;
private set;
}
//...
}
我想我想做的事情如下:
// 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();
可能有更好的方法...如果有,请提出建议。
【问题讨论】:
标签: c# asp.net c#-3.0 collections