Reputation: 361
What is the meaning of {0}\{1}
in c#, it returns some string, but in which format and what kind of string?
Upvotes: 4
Views: 28150
Reputation: 223247
It means that it is expecting parameters to be replaced in string. something like.
string.Format("{0}{1}","parameter1","parameter2");
You may see: Composite Formatting
A composite format string and object list are used as arguments of methods that support the composite formatting feature. A composite format string consists of zero or more runs of fixed text intermixed with one or more format items. The fixed text is any string that you choose, and each format item corresponds to an object or boxed structure in the list. The composite formatting feature returns a new result string where each format item is replaced by the string representation of the corresponding object in the list.
Upvotes: 10
Reputation: 180934
They are format specifier, used with string.Format
or StringBuilder.AppendFormat
and similar functions.
See the manual for string.Format for a detailed explanation.
Upvotes: 2
Reputation: 37566
These are the arguments/params usually used in the string format function:
DateTime dat = new DateTime(2012, 1, 17, 9, 30, 0);
string city = "Chicago";
int temp = -16;
string output = String.Format("At {0} in {1}, the temperature was {2} degrees.",
dat, city, temp);
Console.WriteLine(output);
// The example displays the following output:
// At 1/17/2012 9:30:00 AM in Chicago, the temperature was -16 degrees.
See the documentation
Upvotes: 8