I have a statement where a string is assigned in the following manner:
for (int i = 0; i < x; i++)
{
Foo.MyStringProperty = "Bar_" + i.ToString();
/* ... */
}
Are there any performance differences between i.ToString()
or just plain i
, as both are just converted to the (culture invariant?) string equivalent?
I am well aware of the existence of String.Concat()
, String.Format
, StringBuilder
, etc., but for the sake of this case, lets assume I may only use +
concatenation.
Thanks in advance.
ToString()
uses the current culture. If you want culture-independent conversion you would have to useToString(CultureInfo.InvariantCulture)
(This is more important when dealing with floating point numbers than with integers). – Skat