Beginner C# question here.
I've got a console app with a table of three columns and ready-to-go variables and I'm writing the output.
The table format, in case it's helpful:
const string table = "{0,-25}{1,-4}{2,-15:f2}";
\\n works fine if the WriteLine is just plain text in quotation marks, such as
Console.WriteLine("--------------------------------------------------\n");
But I'm lost as to where I put the /n in the table formatted WriteLine, where the final column contains a variable. Example:
Console.WriteLine(table, "Total cost of paint", ":", paintTotalWithVAT);
I vaguely remember another way of adding the variable - as an aside, the {0} method of place-holding the variable and then declaring it at the end of the brackets seems to not work within the table format - but I'd greatly appreciate some help on this. Ideally I want to have a currency symbol before my variable output (in decimal format) so that would impact the format I need
It's getting a little messy filling my output with a load of empty WriteLines..!
You can put it inside your table
string:
const string table = "{0,-25}{1,-4}{2,-15:f2}\n";
Or if that isn't feasible for some reason you can concatanate it to the string at the WriteLine:
Console.WriteLine(table+"\n", "Total cost of paint", ":", paintTotalWithVAT);
are you trying to add a new line at the end? just concatenate a new string at the end
Console.WriteLine(table, "Total cost of paint", ":", paintTotalWithVAT, "\n");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.