-3

First, my apologies if the title little strange, cause i'm little confused to make title for this problem.

Okay the problem is, it's possible using '\t' outside quote function on 'Console.WriteLine'. I've code like this.

Console.WriteLine("===============================================================================");
Console.WriteLine("| \tNo \t| \tProduct name \t| \tQty \t| \tPrice \t|");
Console.WriteLine("| \t1. \t| \tChicken Nugget \t|" + qty1 + price);
Console.WriteLine("| \t2. \t| \tTempe Nugget \t|" + qty2 + price);
Console.WriteLine("| \t3. \t| \tTofu Nugget \t|" + qty3 + price);
Console.WriteLine("===============================================================================");

So, i want to make variable (qty1, qty2, qty3, and price) parallel to column Qty and Price. It's possible? result with code above

Aditya Rizky
  • 19
  • 1
  • 2
  • 4

2 Answers2

0
Console.WriteLine("===============================================================================");
Console.WriteLine("| \tNo \t| \tProduct name \t| \tQty \t| \tPrice \t|");
Console.WriteLine("| \t1. \t| \tChicken Nugget \t|\t" + qty1 + "\t|\t" + price + "\t|");
Console.WriteLine("| \t2. \t| \tTempe Nugget \t|\t" + qty2 + "\t|\t" + price + "\t|");
Console.WriteLine("| \t3. \t| \tTofu Nugget \t|\t" + qty3 + "\t|\t" + price + "\t|");
Console.WriteLine("===============================================================================")
0

Use string.format which gives you more control over formatting

Ali
  • 1
  • 1
  • 2
    `Console.WriteLine` is using format in same manner as `string.Format` – Fabio Mar 15 '17 at 04:25
  • You could improve your answer by describing how string.format would solve the problem - for example with a code snippet that shows how to pass in the tabs... – Greg the Incredulous Mar 15 '17 at 04:26
  • Hope that this is what you were tried to say : `Console.WriteLine("| \t 1 \t| \t {0} \t| \t {1} \t| \t {2} \t|","Chicken Nugget",Qty,Price );` – sujith karivelil Mar 15 '17 at 04:32