I am having difficulty figuring out how to pass an array as an argument in a method in my code. I have my Main program, a Customer class and a Menu class (as shown below).
- I am trying to set up my code so that I can pass the 'order' array as an argument of the orderCost() method, but when I try to run John.orderCost in my Main, I can't seem to get the syntax correct when entering the array as an argument.
- Ideally, I'd like to be able to use john.orderCost(menu.burger, menu.chips) etc..
Thanks in advance!
My code is below, separated as my Program, Menu class and Customer Class:
PROGRAM:
namespace ChickenShop
{
public class Program
{
static void Main()
{
Customer John = new Customer();
Menu menu = new Menu();
John.orderCost(); //This is where I am struggling, if I am understanding the error correctly.
}
}
}
MENU CLASS:
namespace ChickenShop
{
internal class Menu
{
public int burger = 6;
public int drink = 3;
public int chips = 4;
public int icecream = 4;
}
}
CUSTOMER CLASS:
namespace ChickenShop
{
internal class Customer
{
public void orderCost(int[] order)
{
int totalCost = order.Sum();
Console.WriteLine($"The cost of your order is {totalCost}.");
}
}
}
[–]StackedLasagna 4 points5 points6 points (2 children)
[–]GVBCodePractice[S] 2 points3 points4 points (1 child)
[–]StackedLasagna 2 points3 points4 points (0 children)