2010-05-17 89 views

回答

14

当你不指定它应该投它是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。否则,很容易发生意外丢失数据。