<p>I have a function that takes, amongst others, a parameter declared as <em>int privateCount</em>.  When I want to call ToString() on this param, ReSharper greys it out and marks it as a redundant call.  So, curious as I am, I remove the ToString(), and the code still builds!</p>

<p>How can a C# compiler allow this, where <em>str</em> is a string?</p>

<p><code>str += privateCount +</code> ...</p>

[{'answer_id': 74495, 'author': 'Haacked', 'author_id': 598, 'author_profile': 'https://Stackoverflow.com/users/598', 'pm_score': 5, 'selected': True, 'text': '<p>The + operator for string is overloaded to call String.Concat passing in the left and right side of the expression. Thus:</p>\n\n<pre><code>string x = "123" + 45;\n</code></pre>\n\n<p>Gets compiled to:</p>\n\n<pre><code>String.Concat("123", 45);\n</code></pre>\n\n<p>Since String.Concat takes in two objects, the right hand side (45) is boxed and then ToString() is called on it.</p>\n\n<p>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.</p>\n'}, {'answer_id': 74546, 'author': 'Stephen Deken', 'author_id': 7154, 'author_profile': 'https://Stackoverflow.com/users/7154', 'pm_score': 2, 'selected': False, 'text': "<p>C# automatically converts the objects to strings for you.  Consider this line of code:</p>\n\n<pre><code>aString = aString + 23;\n</code></pre>\n\n<p>This is valid C#; it compiles down to a call to String.Concat(), which takes two objects as arguments.  Those objects are automatically converted to string objects for you.</p>\n\n<p>The same thing occurs when you write:</p>\n\n<pre><code>aString += 23;\n</code></pre>\n\n<p>Again, this compiles down to the same call to String.Concat(); it's just written differently.</p>\n"}, {'answer_id': 74606, 'author': 'Drejc', 'author_id': 6482, 'author_profile': 'https://Stackoverflow.com/users/6482', 'pm_score': 1, 'selected': False, 'text': '<p>This is a valid bad practice, as you must think twice if the variable is a string or an int. What if the variable would be called myInt?</p>\n\n<pre><code>myInt = myInt + 23;\n</code></pre>\n\n<p>it is more readable and understandable in this form?</p>\n\n<pre><code>myInt = mInt + "23";\n</code></pre>\n\n<p>or even:</p>\n\n<pre><code>myInt = string.Format("{0}{1}", myInt, 23);\n</code></pre>\n\n<p>We know from the code that it is a string and not an integer.</p>\n'}, {'answer_id': 75404, 'author': 'Thomas Danecker', 'author_id': 9632, 'author_profile': 'https://Stackoverflow.com/users/9632', 'pm_score': 3, 'selected': False, 'text': '<p>It is not only bad practice, but also less performant: The integer has to be boxed because String.Concat expectes an object while int.ToString() does not require boxing.</p>\n'}]
['https://Stackoverflow.com/questions/74471', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8741/']