本文整理汇总了C#中Account.Debit方法的典型用法代码示例。如果您正苦于以下问题:C# Account.Debit方法的具体用法?C# Account.Debit怎么用?C# Account.Debit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Account
的用法示例。
在下文中一共展示了Account.Debit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transfer
public void Transfer(Account source, Account destination, int amount)
{
lock (source)
{
lock (destination)
{
source.Debit(amount);
destination.Credit(amount);
}
}
}
示例2: Main
static void Main(string[] args)
{
/*
* Account Class Test
*/
Console.WriteLine("********** Account Class Test **********");
Console.WriteLine("");
// Create new account
decimal openningAmount = 65.12M;
Account account = new Account(openningAmount);
// Display openning balance
Console.WriteLine("Openning balance for account is {0:C}", account.Balance);
Console.WriteLine("");
// Test withdraw amount exceeds balance
decimal excessWithdraw = 1000M;
account.Debit(excessWithdraw);
Console.WriteLine("Try to withdraw {0:C} from account. Unchanged balance is {1:C}",
excessWithdraw, account.Balance);
Console.WriteLine("");
// Test a proper withdraw amount
decimal properWithdraw = 5.12M;
account.Debit(properWithdraw);
Console.WriteLine("Withdraw {0:C} from account. New balance is {1:C}", properWithdraw, account.Balance);
Console.WriteLine("");
// Test deposit into account
decimal deposit = 0.01M;
account.Credit(deposit);
Console.WriteLine("Deposit {0:C} into account. New balance is {1:C}", deposit, account.Balance);
Console.WriteLine("");
// Test creating account with a negative openning balance
openningAmount = -10M;
Console.WriteLine("Try to create new account with {0:C}", openningAmount);
try
{
Account negative = new Account(openningAmount);
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine(e.Message);
}
finally
{
Console.WriteLine("");
}
/*
* SavingAccount Class Test
*/
Console.WriteLine("");
Console.WriteLine("********** SavingAccount Class Test **********");
Console.WriteLine("");
// Create new Saving Account
decimal interestRate = 0.05M;
openningAmount = 800M;
SavingsAccount savingsAccount = new SavingsAccount(openningAmount, interestRate);
// Display openning balance
Console.WriteLine("Openning balance for savings account is {0:C}", savingsAccount.Balance);
Console.WriteLine("Having an interest rate of {0:P}", savingsAccount.InterestRate);
Console.WriteLine("");
// Test deposit into account (from Account Class)
deposit = 100M;
savingsAccount.Credit(deposit);
Console.WriteLine("Deposit {0:C} into savings account. New balance is {1:C}",
deposit, savingsAccount.Balance);
Console.WriteLine("");
// Test calculate interest
decimal interestAmount = savingsAccount.CalculateInterest();
Console.WriteLine("Calculated amount from {0:P} interest is {1:C}", interestRate ,interestAmount);
Console.WriteLine("");
/*
* CheckingAccount Class Test
*/
Console.WriteLine("");
Console.WriteLine("********** CheckingAccount Class Test **********");
Console.WriteLine("");
// Create new Checking Account
decimal transactionFee = 0.02M;
openningAmount = 500M;
CheckingAccount checkingAccount = new CheckingAccount(openningAmount, transactionFee);
// Display openning balance
Console.WriteLine("Openning balance for checking account is {0:C}", checkingAccount.Balance);
Console.WriteLine("Having a transaction fee of {0:C}", checkingAccount.TransactionFee);
Console.WriteLine("");
// Test deposit into checking account (overrides Account Class)
deposit = 100M;
checkingAccount.Credit(deposit);
//.........这里部分代码省略.........
示例3: ArrangeAndAct
public void ArrangeAndAct()
{
accountId = Guid.NewGuid();
var account = new Account(accountId, 200);
account.Debit(300);
account.Debit(300);
account.ClearEvents();
account.Debit(300);
events = account.UncommittedEvents.ToArray();
}
示例4: DebitTest_Insufficient
public void DebitTest_Insufficient()
{
Account target = new Account(15.00, 1, "test account", "11/12/12"); // TODO: Initialize to an appropriate value
double amount = 25.00; // TODO: Initialize to an appropriate value
double expected = 15.00; // TODO: Initialize to an appropriate value
double actual;
actual = target.Debit(amount);
Assert.IsTrue((actual == expected), "Debit Test with insufficient funds passes.");
Assert.IsFalse(actual != expected, "Debit Test with insufficient funds fails.");
}
示例5: TransferMoney
public override void TransferMoney(decimal amt, Account.Account otherAccount)
{
var orders = getLockOrder(this, otherAccount as holdwaitAccount);//Resolve DeadLock
lock (orders[0].Lock)
{
Thread.Sleep(20);
lock (orders[1].Lock)
{
this.Credit(amt);
otherAccount.Debit(amt);
Thread.Sleep(2);
Console.WriteLine(amt + " Transfered from " + this.orderNumber + " To " + otherAccount.orderNumber);
}
}
}
示例6: TransferMoney
public override void TransferMoney(decimal amt, Account.Account otherAccount)
{
Mutex[] locks = { this.Lock, (otherAccount as MutexAccount).Lock };
if (WaitHandle.WaitAll(locks, 1000))//All Locks or one approach
try
{
this.Credit(amt);
Thread.Sleep(20);
otherAccount.Debit(amt);
Console.WriteLine(amt + " Transfered from " + this.orderNumber + " To " + otherAccount.orderNumber);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
foreach (var Lock in locks)
Lock.ReleaseMutex();
}
}