本文整理汇总了C#中System.Currency.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Currency.Equals方法的具体用法?C# Currency.Equals怎么用?C# Currency.Equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Currency
的用法示例。
在下文中一共展示了Currency.Equals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CurrencyHasValueEquality
public void CurrencyHasValueEquality()
{
var currency1 = new Currency("USD");
var currency2 = new Currency("USD");
object boxedCurrency2 = currency2;
currency1.Equals(currency2).ShouldBe(true);
currency1.Equals(boxedCurrency2).ShouldBe(true);
}
示例2: PrintCurrency
/// <summary>
/// this can be reused for whatever currency type you would like to add if you need more in the future
/// </summary>
/// <param name="currency"></param>
/// <param name="userBalance"></param>
/// <returns></returns>
public static String PrintCurrency(Currency currency, decimal dollarAmmount)
{
if (currency.Equals(Currency.USD))
{
return String.Format("{0:C}", dollarAmmount);
}
else
{
decimal exchangeRate = GetTransferRate(Enum.GetName(typeof(Currency), currency));
return String.Format("{0:f2} {1}", (dollarAmmount * exchangeRate), Enum.GetName(typeof(Currency), currency));
}
}
示例3: EqualsTest
public void EqualsTest()
{
string currencyName = "US";
string symbol = "USD";
Currency target = new Currency(currencyName, symbol);
bool actual;
actual = target.Equals(null);
Assert.AreEqual(false, actual);
// currencies are equal if the symbols match
currencyName = "United states dollar";
symbol = "USD";
Currency target2 = new Currency(currencyName, symbol);
actual = target.Equals(target2);
Assert.AreEqual(true, actual);
}