3 ms·
> IIRC it has something to do with how they both descend from Object... It's far less interesting than that. The truth is that the symbol + means a wide variet
by chowells 1y ago
> IIRC it has something to do with how they both descend from Object...
It's far less interesting than that. The truth is that the symbol + means a wide variety of different things in the language, and it uses compile-time type information to select exactly which of those things it means. In the case where either operand is a string, it means string concatenation, with string conversion for a non-string operand if one exists.
That specific conversion part is the only thing that cares that stuff descends from Object. The conversion algorithm is "call ToString() and let dynamic dispatch sort it out."
(For completeness, the other meanings are various forms of addition, but adding two doubles is a different machine instruction than adding two floats. It really does still need to use type information to figure out which of those operations it is.)
- deleted 1y ago[deleted]