Formatting my string
8 answers
The method String.Format
accepts a format string followed by one to many variables to be formatted. The format string is made up of placeholders, which are essentially places to place the values ββof the variables that you pass to the function.
Console.WriteLine(String.Format("{0}, {1}, {2}", var1, var2, var3));
+2
source to share
use string.format and put the individual format specifiers inside curly braces, after the number and colon, as in
string s = string.Format(
" {0:d MMM yyyy} --- {1:000} --- {2:#,##0.0} -- {3:f}",
DateTime.Now, 1, 12345.678, 3e-6);
and as you can see from the example, you don't need single quotes to delimit literals, anything not inside curly braces will be output literally
+2
source to share