What is the advantages between the syntax in C# (or other programmign languages) to displaying text in an application.
decimal fooTotal = 2.53;
For example:
Console.WriteLine("Filtered total: {0:c}", fooTotal);
VS
Console.WriteLine("Filtered total: " + fooTotal);
I see the first method in more examples and books (Current the MVC 3 book I’m going through) but I was taught method 2. I could hypothesize that method one would allow you to change values quickly? The first value would also be displayed in currency which I”m also assuming is more succinct ?
The first form applies the
cformat specifier to the value, which treats it as a currency. To change the second snippet to behave similarly, you could use:I’ll often use string concatenation (the second form) for just a single parameter, but when I’ve got multiple values to include or I want to specify a format specifier, I’ll use
string.Formator the equivalent. (Console.WriteLineeffectively callsstring.Formatfor you here.)