> ## Content Index
> Fetch the complete content index at: https://davidzych.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# When doing string concatenation in C#, why don't you have to call ToString on non string variables?
- URL: https://davidzych.com/when-doing-string-concatenation-in-c-why-dont-you-have-to-call-tostring-on-non-string-variables/
- Published: 2013-10-23T13:11:48.000Z
- Updated: 2026-11-19T17:32:39.000Z
- Author: David Zych
- Tags: boxing, C#, concatenation, string, unboxing, #Import 2026-11-20 21:02

To get the string representation of a variable, in this case we’ll use `int`, there is no implicit conversion from `int` to `string` so you can call the `ToString` method:

```
string s = myInt; //INVALID!!
string s = myInt.ToString(); // Valid!

```

When concatenating with another string, though, you don’t have to do so:

```
string s = "First string " + myInt; //No ToString??!?

```

**Why?**

When performing string concatenation like above, the code is compiled to actually use the `string.Concat(object, object)` method. So our example above actually compiles to:

```
string s = string.Concat((object)"First string ", (object)myInt);

```

Notice the casts to object for both the `string` and `int` variables. This is also known as [boxing](http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx?ref=davidzych.com):

> Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type. When the CLR boxes a value type, it wraps the value inside a System.Object and stores it on the managed heap. Unboxing extracts the value type from the object. Boxing is implicit; unboxing is explicit. The concept of boxing and unboxing underlies the C# unified view of the type system, in which a value of any type can be treated as an object.

The boxing and unboxing processes, as with anything, *technically* incur a performance penalty, but in the grand scheme of things [they are nothing to worry about.](http://msmvps.com/blogs/jon%5Fskeet/archive/2008/10/08/why-boxing-doesn-t-keep-me-awake-at-nights.aspx?ref=davidzych.com)

When it comes to string concatentation *technically* `string s = "First string " + myInt.ToString();` is faster because it will use the `string.Concat(string, string)` overload. But the performance difference is so negligible that you should use whatever you find most readable.