Я реализую следующий код для удаления элемента из списка
// RemoveRole is a member function in a class for Person
// roles is defined as
// List<PersonOrganisationRoleModel> roles;
// And properly populated prior to this function call
public void RemoveRole(string RoleName)
{
// I am creating an object that needs to be matched in the list
PersonOrganisationRoleModel role = new PersonOrganisationRoleModel(OrganisationID, PersonID, RoleName)
// "role" is now properly constructed, and is matching an exact copy of one of the objects in "roles"
// the expectation now is the the object "role" must be matched with one of the objects in "roles",
// and that one be removed
roles.Remove(role);
}
Но вызов функции «Удалить» из списка «ролей» не удаляет элемент в списке, который содержит точный те же значения.
Насколько я понимаю, это должно работать (это только обратное значение List.Add