The C# spec probably says so, but even though nothing showed up in my search, that's not the answer I'm looking for.
I'm looking for scenarios that show that calling operator methods (like op_Addition
) or property accessors (like get_Length
) directly might be a bad idea. Bad enough for the designers of the C# language to stop us from doing it. (See compiler error CS0571.)
One fairly common scenario where it would be useful to have this ability is where a Func<T>
delegate should return the value of a property. You can't make the get accessor the method of the delegate, either. There's a simple work-around (use () => someObject.SomeProperty
), but, even aside from the overhead, it's not as clear as someObject.get_SomeProperty
.
The one complication I see is that, when a type defines multiple conversions to different types, the methods would have the same signature with different return types, which C# doesn't allow either. But that's a different question.