Redundant Call to Object.ToString()

Redundant Call to Object.ToString()

The + operator for string is overloaded to call String.Concat passing in the left and right side of the expression. Thus:

string x = "123" + 45;

Gets compiled to:

String.Concat("123", 45);

Since String.Concat takes in two objects, the right hand side (45) is boxed and then ToString() is called on it.

Note that this "overloading" is not via operator overloading in the language (aka it's not a method named op_Addition) but is handled by the compiler.

原文地址:https://www.cnblogs.com/chucklu/p/4754262.html