Lyrk Lyrk - 3 years ago 56
C# Question

What is "4" doing in below code piece?

I understand

is the 1st argument as
is the second argument as
but what is

Console.WriteLine("End counting {0} : {1, 4:N0} ms", id, sw.Elapsed.TotalMilliseconds);

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download