C#里面有两个关键字不懂是什么意思
implicit和explicit这两个是什么意思,什么作用publicstaticimplicitoperatorfloat(Currencyvalue){return...
implicit和explicit这两个是什么意思,什么作用
public static implicit operator float(Currency value)
{
return value.dollars + (value.cents / 100.0f);
}
public static explicit operator Currency(float value)
{
checked
{
uint dollars = (uint)value;
ushort cents = Convert.ToUInt16((value - dollars) * 100);
return new Currency(dollars, cents);
}
} 展开
public static implicit operator float(Currency value)
{
return value.dollars + (value.cents / 100.0f);
}
public static explicit operator Currency(float value)
{
checked
{
uint dollars = (uint)value;
ushort cents = Convert.ToUInt16((value - dollars) * 100);
return new Currency(dollars, cents);
}
} 展开
2个回答
展开全部
public static implicit operator float(Currency value)
表示Currency到float是隐式转换,如:
Currency a;
float b = a;
public static explicit operator Currency(float value)
表示float到Currency需要强制转换,如:
float a;
Currency b = (Currency)a;
表示Currency到float是隐式转换,如:
Currency a;
float b = a;
public static explicit operator Currency(float value)
表示float到Currency需要强制转换,如:
float a;
Currency b = (Currency)a;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询