For:
Console.WriteLine("Hi there, {0} {1}!", userName, userSurname);
Your first call resolves to: Console.WriteLine(string,object,object)
IN IL
IL_000d: ldstr "Hi there, {0} {1}!"
IL_0012: ldloc.0
IL_0013: ldloc.1
IL_0014: call void [mscorlib]System.Console::WriteLine(string,
object,
object)
For:
Console.WriteLine("Hi there, " + userName + " " + userSurname + "!" );
While your second statement makes a call to string.Concat
method.
IL_0042: call string [mscorlib]System.String::Concat(string[])
IL_0047: call void [mscorlib]System.Console::WriteLine(string)
If you look at the code using ILSpy, you will see that the part where you have used +
for string concatenation is replaced with call to string.Concat
method
string userName = "Test";
string userSurname = "Test2";
Console.WriteLine("Hi there, {0} {1}!", userName, userSurname);
Console.WriteLine(string.Concat(new string[]
{
"Hi there, ",
userName,
" ",
userSurname,
"!"
}));
With respect to difference in performance, I believe if there is any its going to be negligible.