检查下面的代码:
class Money
{
public Money(decimal amount)
{
Amount = amount;
}
public decimal Amount { get; set; }
public static implicit operator decimal(Money money)
{
return money.Amount;
}
public static explicit operator int(Money money)
{
return (int)money.Amount;
}
}
我不明白它在我的代码中会有什么用,我不能做一个像这样的方法:
public static int returnIntValueFrom(Money money)
{
return (int)money.Amount;
}
实施起来不是更容易更清晰吗?