The assignment operator, like some others, cannot really be redefined (see MSDN ). But if you have access to the source code for the Person class, then to solve your problem, it is enough to inherit the Person class from the IClonable interface and implement this interface like this:
public class Person : IClonable { // тут ваши поля и методы public object Clone() { var personClone = new Person(); //тут копируем в новую сущность нужные свойства return personClone; } }
After that, you can easily copy elements, for example:
Person p1 = new Person() { //присвоили значения полям } Person p2 = p1.Clone();
In this case, p2 will receive a new reference to its own Person object. True, you will have to manually copy the collection elementwise in a loop, since the Clone method implemented in standard collections makes incomplete copying and in the case of elements of the reference type, it copies links. But in this case, you can provide a static method in the Person class that receives the collection as input and returns a copy of it.
Personclass from theIClonableinterface and implement theClonemethod in your own way. This is exactly what it is intended for - rdorn pmnew Person(this)compiled, aPersonmust have aPerson(Person other)constructorPerson(Person other). - VladD