+ 3
One of the overloads of WriteLine method works by accepting a string as the format, and multiple values following the format to be used as replacement for value anchors (the {n} in format string). The arguments following the format can be referred to by their index. The first one following the format string is indexed 0, the second one following the format string is indexed 1, and so forth. The {n} will be replaced by the value of argument referred by index 'n''. So, {0} will be replaced by value of variable `x`, {1} will be replaced by value of `y`. If there are more values; you must match number of anchors {} with number of arguments following the format string. For that example you gave (despite incompleteness and syntax error): int x = 4, y = 2; Console.WriteLine("x={0}, y={1}",x, y); int x = 4, y = 2; "x={0},y={1}" is the format string. `x` is the first argument following format string, indexed 0. `y` is the second argument following format string, indexed 1. Output: x=4,y=2 Hth, cmiiw
28th Apr 2019, 9:35 AM
Ipang