I need Method to print List as table in console application and preview in convenient format like this:
Pom_No Item_Code ordered_qty received_qty 1011 Item_Code1 ordered_qty1 received_qty1 1011 Item_Code2 ordered_qty2 received_qty2 1011 Item_Code3 ordered_qty3 received_qty3 1012 Item_Code1 ordered_qty1 received_qty1 1012 Item_Code2 ordered_qty2 received_qty2 1012 Item_Code3 ordered_qty3 received_qty3
Print DataTable , DataView , DataSet , DataRow[] (= DataTable. Select() ) Print Columns. Print in tabular format and list format.
Open Chrome developer tools (press F12). Then create an array of hashes of data. The hash keys will be used as table columns, and the values will be used as table rows. Apparently console.
Your main tool would be
Console.WriteLine("{0,5} {1,10} {2,-10}", s1, s2, s3);
The ,5
and ,10
are width specifiers. Use a negative value to left-align.
Formatting is also possible:
Console.WriteLine("y = {0,12:#,##0.00}", y);
Or a Date with a width of 24 and custom formatting:
String.Format("Now = {0,24:dd HH:mm:ss}", DateTime.Now);
With string interpolation you can now write
Console.WriteLine($"{s1,5} {s2,10} {s3,-10}"); Console.WriteLine($"y = {y,12:#,##0.00}");
You don't need to call String.Format()
explicitly anymore:
string s = $"Now = {DateTime.Now,24:dd HH:mm:ss}" + ", " + $"y = {y,12:#,##0.00}" ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With