-3

I understand {0} is the 1st argument as id, {1} is the second argument as sw.Elapsed.TotalMilliseconds but what is 4 for?

Console.WriteLine("End counting {0} : {1, 4:N0} ms", id, sw.Elapsed.TotalMilliseconds);
Mighty Badaboom
  • 6,067
  • 5
  • 34
  • 51
Lyrk
  • 1,936
  • 4
  • 26
  • 48

2 Answers2

2

Here 4 is alignment specifier. It specifies to align the number 4 units right.

Controlling alignment

By default, strings are right-aligned within their field if you specify a field width. To left-align strings in a field, you preface the field width with a negative sign, such as {0,-12} to define a 12-character right-aligned field.`

From String.Format Method - MSDN

Surojit
  • 1,282
  • 14
  • 26
1

It's the alignment. From MSDN (emphasis mine):

Each format item takes the following form and consists of the following components: {index[,alignment][:formatString]}

...

The optional alignment component is a signed integer indicating the preferred formatted field width. If the value of alignment is less than the length of the formatted string, alignment is ignored and the length of the formatted string is used as the field width. The formatted data in the field is right-aligned if alignment is positive and left-aligned if alignment is negative. If padding is necessary, white space is used. The comma is required if alignment is specified.

Heinzi
  • 167,459
  • 57
  • 363
  • 519