How to use the parameter to update the value of a variable in another class? c#

  Uncategorised

Im trying to update the variable Total in another class by trying to get the subtotal from an Order. Then that value will go inside a method in OrderTest.cs that will add on to the value Total from the other class. What am I doing wrong. CS1061: ‘Order does not contain a definition for subtotal.(are you missing a using directive or an assembly reference?)’

My Class Order.cs____________________

class Order {

    
    private static decimal total;
    public static decimal Total { get { return total; } set { total = value; } }
    public static string CustomerName { get; set; }
    public static int OrderNum { get; set; }
    public static decimal SubTotal { get; set; }

    public Order (string customername, int ordernum, decimal subtotal, string Item1, string Item2, string Item3, string Item4)
    {
        
        CustomerName = customername;
        OrderNum = ordernum;
        SubTotal = subtotal;
        item1 = Item1;
        item2 = Item2;
        item3 = Item3;
        item4 = Item4;
    }

Then this is the OrderTest.cs ___________________________

//This method updates the total from the class

    public static void UpdateTotal(decimal UpValue)
    {
        Order.Total += UpValue;
    }

static void Main(string[] args)
    {
        //Declaration of variables 
        char selection;
        int orderEdit;
        int oNum;
        bool endMenue = false;

        //string customername, int ordernum, decimal subtotal, string Item1, string Item2, string Item3, string Item4

        Order order1 = new Order("Fred_Flintsone", 123, 56.75M, "Beef", "Rice", "Bread", "Milk" );
        Order.Total = UpdateTotal(order1.subtotal); //This is where I am having issues trying to get subtotal
        //I want to use the subtotal to update the Total in the Order.cs, using the method called UpdateTotal }

Source: Visual Studio Questions

LEAVE A COMMENT