プログラミングに慣れていません。私は、asp.netとMVCパターンを使いこなしています。コードスニペットを以下に示します。私はそのバランス方式に渡す方法はかなりわからないCurrentAccountMVCパターンを使用してバランスメソッドを表示する方法
public class People:CurrentAccount
{
// Creating customers
public string Name;
public string Surname;
private int _age;
//Setting restriction to account at age 18
public int age
{
get
{
return _age;
}
set
{
if(value>18)
{
_age = value;
}
else
{
throw new ApplicationException("Bank's current policies for having an account is over 18");
}
}
}
CurrentAccount CA;
public People()
{
CA = new CurrentAccount();
}
}
}
public class CurrentAccount : IAccount
{
double balance = 0;
public void deposit(double money)
{
balance += money;
}
public void withdraw(double money)
{
if (balance < 0)
{
balance -= money;
}
else
{
throw new ApplicationException("Insuffient amount");
}
}
public double Balance()
{
return balance;
}
}
そして、私のController`
[HttpGet]
public ActionResult Deposit()
{
return View();
}
[HttpPost]
public ActionResult Deposit(double money)
{
People p = new People()
p.deposit(money);
return View();
}
public ActionResult Balance()
{
People p = new People();
p.Balance();
return View();
}
から継承
マイ人民クラス私は預金とそれを見る後の値を保持します。 お役に立ちましたか? ありがとう
は、なぜあなたは 'だけで行うことはできませんp.balance() '?それはとにかく同じクラスです。 – Prajwal
私はこれが正しく動作しませんと言うことができますから?新しいPeopleオブジェクトを作成しているので、入金した金銭は1回の呼び出し後に失われます。 C#をやっているときはパスカルの場合を使用してください! –
ありがとうと感謝の言葉。どのようにそのメソッドのビューでモデルを渡すだろうか? –