I have a very simple method that takes a string, breaks it into a char array, then creates a new string from the pieces. However it is performing unexpectedly and I don't understand why? Here is a picture of breakpoint. The input string in this case is "20160622".
Edit: Sorry for the pic. Here is the question in text.
internal class Program
private static void Main()
string test = "20160622";
private static string ConvertDateField(string date)
var temp = date.ToCharArray();
var output = temp + temp + temp + temp + "-" + temp + temp + "-" + temp + temp + " 00:00:00";
For your question. The char concat is not a string concat. What happened is that c# is doing Math operation for the chars by casting them to int with ASCII.
The corresponding ascii for temp 1, 2, 3, 4 are 50, 48, 49, 54 which the sum is 201. (what an coincidence)
int + string concat resulted in string so the rest of the string worked as expected.
There is an easier way to perform the convert if it was a DateTime object. You can simply call
dateTime.ToString("yyyy-MM-dd 00:00:00") and you will get the result you want.