Many people want to run or debug C #ProgramYou can display the degree of completion of your program. Here is a way to continuously modify the same line of CMD to display the completion percentage.
Public VoidPrintpercentage (IntFinishedcount,IntTotalcount)
{
DecimalFinishedpercentage = convert. todecimal (finishedcount)/convert. todecimal (totalcount );
Console. setcursorposition (0, Console. cursortop-1);
Console. writeline (finishedpercentage *100). Tostring ("F1") +"%");
}
The purpose of setcursorposition is to reset the cursor to which the parameter indicates (left, top). The bottom line of the current CMD is top. tostring ("f1") indicates retaining a decimal number.
You can also use "\ r" to return the cursor to the current first line, as shown below:
Public VoidPrintpercentage (IntFinishedcount,IntTotalcount)
{
DecimalFinishedpercentage = convert. todecimal (finishedcount)/convert. todecimal (totalcount );
Console. writeline ("\ R"+ (Finishedpercentage *100). Tostring ("F1") +"%");
}
In contrast, the previous one is more flexible and can be located anywhere.