获取和设置变量的一类从另一个类

问题描述:

我心中已经一个shopping_cart.aspx.cs档案与还有一类文件spcart.cs,

i'v a shopping_cart.aspx.cs file & also have a class file spcart.cs,

shopping_cart.aspx.cs

public partial class Ui_ShoppingCart : System.Web.UI.Page
{
    public int tax = 0;   
    public int subtotal = 0;
    public int granttotal = 0;  

    protected void Page_Load(object sender, EventArgs e)
         {
             -------------------------/////some code
         }
   --------------------------------/////some code
}

spcart.cs

public class Spcart
    {     
        public void updatecart(int pid,int qty)
         {
             ---------/////some code
         }
    }

现在我想在类Ui_ShoppingCart 变量税,subtoal和放大器来设置一些值;从类Spcart granttotals,所以我试图 - >

now i want to set some values in class Ui_ShoppingCart variables tax, subtoal & granttotals from class Spcart, so i'd tried-->

Ui_ShoppingCart.tax

但它没有工作.........结果
是否有任何其他的方法来设置这些变量?结果
谁能帮我这个?

but it didnt worked.........
is there any other way to set these variables ???
can anyone help me about this???

我想应该是另一种方式圆

I think it should be the other way round

protected void Page_Load(object sender, EventArgs e)
{
   SpCart cart = new SpCart();
   cart.updateCart(124, 4);

   tax = cart.getComputedTax();
   subTotal = cart.getSubTotal();
   ...
}

我们的想法是这些变量应该独立于SpCart code的。

The idea is those variables should independent of your SpCart code.

public class Spcart
{     
     public void updatecart(int pid,int qty)
     {
         ---------/////some code
     }

     public int getComputedTax()
     {
       //can compute tax here
       int tax = whatever;
       return tax;
     }
}

的计算逻辑仍然可以被分离成其他类

The computation logics can still be separated into some other class