日期:2014-05-17 浏览次数:20979 次
using System;
struct Currency
{
public uint Dollars;
public ushort Cents;
public Currency(uint Dollars,ushort Cents)
{
this.Dollars = Dollars;
this.Cents = Cents;
}
public override string ToString()
{
return string.Format("${0}.{1,-2:00}",Dollars,Cents);
}
public static implicit operator float(Currency value)
{
return value.Dollars + (value.Cents/100.01);
}
}
public class Test
{
public static void Main()
{
Currency Balance = new Currency(10,50);
float D = Balance;
}
}
public static implicit operator float(Currency value)
{
//return value.Dollars + (value.Cents/100.01);
return value.Dollars + (value.Cents/100.01f);
}