我已经看到了某种形式的这前一段时间,但我不记得这是什么所谓,因此对如何实现这样的事情没有任何线索:这个语法叫什么? SomeMoneyFormat f =“€5,00”;
SomeMoneyFormat f = "€ 5,00";
其中要求,可以分析一些过载功能将该字符串转换为SomeMoneyFormat
对象。
我已经看到了某种形式的这前一段时间,但我不记得这是什么所谓,因此对如何实现这样的事情没有任何线索:这个语法叫什么? SomeMoneyFormat f =“€5,00”;
SomeMoneyFormat f = "€ 5,00";
其中要求,可以分析一些过载功能将该字符串转换为SomeMoneyFormat
对象。
当你不指定它应该投它是implicit cast
public static implicit operator SomeMoneyFormat(string d)
{
return new SomeMoneyFormat(d);
}
然后€ 5,00
作为字符串d
更多关于此这里经过: http://msdn.microsoft.com/en-us/library/z5z9kes2(VS.71).aspx
而且,我可以补充说,这只能在没有丢失数据风险的情况下完成。例如,将double
转换为int
将会失去一些精度,因此它是explicit cast
。否则,很容易发生意外丢失数据。
对我来说看起来像是implicit type conversion。