Alex Rivera | Logout

Why can '=' not be overloaded in C#?

Asked 2009-03-01T06:23:43.647
25

I was wondering, why can't I overload '=' in C#? Can I get a better explanation?

Edit
Report

1 Answer

3

I don't think there's any really particular single reason to point to. Generally, I think the idea goes like this:

  • If your object is a big, complicated object, doing something that isn't assignment with the = operator is probably misleading.

  • If your object is a small object, you may as well make it immutable and return new copies when performing operations on it, so that the assignment operator works the way you expect out of the box (as System.String does.)

answered 2009-03-01T06:32:34.203

Your Answer