Answer the question
In order to leave comments, you need to log in
How to overload assignment operator, c#?
Hello, I read on a couple of forums that it is impossible to overload this operator. How to solve this problem? '
{
public static void operator = (Person p, Person p1);
}`
Answer the question
In order to leave comments, you need to log in
From a C# perspective, what you want is not what you want. Unlike C++, where operator overloading makes it possible to generate individual behavior for each user-defined type, C# has built two basic behaviors for you - a reference type and a value type - and prompts you to choose one of them.
You need to reformulate the task into a more general one, and understand what you really want to do, and why you need to redefine the assignment. Judging by the name of the class (Person), you are clearly doing something wrong with it.
Isn't this a mix of assignment and copy constructor? The author wants behavior in the spirit of:
Person p1 = new Person( ...);
Person p = new Person(p1);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question