+ 1
Can someone please explain each part of this code: Console.Write("{0, 8}", tipRate.ToString("F"));
What this line of code does in C#? for (tipRate = LowRate; tipRate <= MAXRATE; tipRate += TIPSTEP) Console.Write("{0, 8}", tipRate.ToString("F"));
1 ответ
+ 2
It is a for loop
There is a variable tipRate;
This tipRate variable is assigned to LowRate
The loop then loops from tipRate (which has the value of LowRate) to MAXRATE
With steps that are defined in TIPSTEP.
Console.Write shows the value of tipRate
{0,8}
0 stands for the index of the place holder
8 stands for alignment component (first time I see this being used)
tipRate.ToString("F");
Convert the value of tipRate to a string
With "F" a Fixed point format specifier by default after the decimal point the number digits are 2.
http://www.c-sharpcorner.com/UploadFile/c25b6d/fixed-point-f-format-specifier-in-C-Sharp/
link about alignment operator
https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting