1

Unable to overloaded unary operator = in c#. it is giving error.

public static Result operator =(Int32 iv)
{
    return new Result(){iv=iv};
}
Thulasiram
  • 8,432
  • 8
  • 46
  • 54
  • Perhaps a use-case would help. As it stands there is only one correct answer: you can't. If we knew how/why you were planning on using this, we might be able to offer better methods. – Jonathon Reinhart Jan 20 '14 at 22:59

2 Answers2

2

You cannot overload the = operator in C#.

From 7.2.2 Operator overloading:

In particular, it is not possible to overload member access, method invocation, or the =, &&, ||, ?:, checked, unchecked, new, typeof, as, and is operators.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
2

You cannot overload the assignment operator in C#.

However, there is a good solution here.

Community
  • 1
  • 1
nvoigt
  • 75,013
  • 26
  • 93
  • 142