本文整理汇总了C#中Coin.ToValue方法的典型用法代码示例。如果您正苦于以下问题:C# Coin.ToValue方法的具体用法?C# Coin.ToValue怎么用?C# Coin.ToValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coin
的用法示例。
在下文中一共展示了Coin.ToValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddCoin
public void AddCoin(Coin coin, int ammount)
{
Contract.Requires(ammount > 0);
Contract.Requires(Contract.Exists(Wallet, el => (decimal)el.Element("Type") == coin.ToValue()),
"PRE: The coin type must exist in the wallet");
Contract.Ensures(ammount <= (int)Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single().Element("Ammount"));
Contract.Ensures(Contract.OldValue((int)Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single().Element("Ammount")) + ammount ==
(int)Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single().Element("Ammount"));
XElement soughtCoin = Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single();
soughtCoin.Element("Ammount").Value = ((int)soughtCoin.Element("Ammount") + ammount).ToString();
Database.Save("CoinDatabase.xml");
}
示例2: InsertCoin
public TransactionResult InsertCoin(Coin coin)
{
Contract.Requires(state == State.ProductChosen || state == State.MoneyInserted);
Contract.Ensures(state == State.MoneyInserted);
InsertedValue += coin.ToValue();
CoinMan.AddCoin(coin, 1);
state = State.MoneyInserted;
if (SelectedProduct != null && !CoinMan.CheckChange(SelectedProduct.Price, InsertedValue))
return TransactionResult.SuccessButNoChange;
return TransactionResult.Success;
}
示例3: EjectCoin
public void EjectCoin(Coin coin, int ammount, LinkedList<Coin> coinCase)
{
Contract.Requires(coinCase != null);
Contract.Requires(ammount >= 0);
Contract.Requires(Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Select(c => (int)c.Element("Ammount")).Single() >= ammount,
"PRE: There must be enough of coins of given type to eject");
Contract.Ensures(Contract.OldValue(coinCase.Where(c => c == coin).Count()) + ammount == coinCase.Where(c => c == coin).Count(),
"POST: The ejected coins must be in the case");
Contract.Ensures(Contract.OldValue((int)Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single().Element("Ammount")) - ammount ==
(int)Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single().Element("Ammount"));
XElement soughtCoin = Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single();
soughtCoin.Element("Ammount").Value = ((int)soughtCoin.Element("Ammount") - ammount).ToString();
for (int i = 0; i < ammount; ++i)
coinCase.AddLast(coin);
Database.Save("CoinDatabase.xml");
}