0

can someone pls explain the function of {0} why can't i use +x to display the results of code instead

2nd Nov 2016, 6:26 PM
Luqmaan Mudasiru
Luqmaan Mudasiru - avatar
6 odpowiedzi
+ 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.
2nd Nov 2016, 8:14 PM
Tamra
Tamra - avatar
+ 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.
2nd Nov 2016, 10:36 PM
Wen Qin
Wen Qin - avatar
+ 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
4th Nov 2016, 2:14 PM
Michael Dolence
0
exactly bruv
2nd Nov 2016, 8:39 PM
Luqmaan Mudasiru
Luqmaan Mudasiru - avatar
0
okay thanks
3rd Nov 2016, 7:44 AM
Luqmaan Mudasiru
Luqmaan Mudasiru - avatar
0
@Micheal Dolence, that's helpful thanks
4th Nov 2016, 6:38 AM
Luqmaan Mudasiru
Luqmaan Mudasiru - avatar