0
can someone pls explain the function of {0} why can't i use +x to display the results of code instead
6 Answers
+ 10
Like this?
Console.WriteLine("You entered " + x + ".");
//as compared to
Console.WriteLine("You entered {0}.", x);
It can be a matter of preference, but if you're putting out a lot of variables in one statement, using placeholders can look neater.
+ 7
1. it is like what Tamra stated.
2. You can do that. Although SoloLearn courses/lessons normally do the {0} method, it still works if you just do the "+" method.
+ 3
It depends on what you are doing what technique you should use, there are performance implications (usually minor) for each way of concatenating strings.
Additionally in C# 6.0 there is a friendlier way to use string format
string s = String.Format("{0}", x);
Is the same as this:
string s = quot;{x}";
"How to: Concatenate Multiple Strings (C# Programming Guide)" : https://msdn.microsoft.com/en-us/library/ms228504.aspx
0
exactly bruv
0
okay thanks
0
@Micheal Dolence, that's helpful thanks