【发布时间】:2020-07-24 05:06:59
【问题描述】:
我有 3 个数组。一个用于项目编号,一个用于项目描述,一个用于价格。
我希望能够从中创建一个“表”,因此它的内容如下:
Item Number: Description: Price:
50 Water $50
752 Carrots $.60
67 Ice $9
等等。我尝试使用 foreach 语句创建方法,然后调用这些方法。它可以工作,但不能并排打印。有关如何解决此问题的任何想法?
这里是代码 `
using static System.Console;
class FoodOrder
{
static void Main()
{
//Variables used in the method
const int MENU_ASTERIKS = 42;
string description = "Description", itemNumber = "Item number", price = "Price";
string[] itemDescription = { "Cheese Frise", "Corn Dogs", "Cheeseburger", "Hamburger", "Fries", "Fountain Drink", "Philly Cheese Steak", "Tacos" };
int[] itemNumList = { 20, 23, 25, 31, 35, 38, 39, 34, };
double[] itemPrice = { 2.95, 1.95, 2.25, 3.10, 4.50, 3.65, 5.00, 2.75};
Write("\t");
for (int x = 0; x < MENU_ASTERIKS; ++x) //Creates a top border for the menu with the prices and is the start of the menu
Write("*");
WriteLine(" ");
Write("\t {0}\t{1}\t{2}", itemNumber, description, price);
DisplayItemNum(itemNumList); DisplayDescriptions(itemDescription);
}
//Method to dispay item number
private static void DisplayItemNum( params int[] itemNums)
{
WriteLine("\n");
foreach (int number in itemNums)
WriteLine("\t {0} ", number);
}
//Method to Display item Number
private static void DisplayDescriptions(params string[] desc)
{
WriteLine("\n");
foreach (string objects in desc)
WriteLine("\t\t\t{0}", objects);
}
}
`
【问题讨论】:
-
请输入您的代码而不是图像。会更容易阅读
-
@D.J.我试过了,但这只是将数组中的对象写在同一行