2010-05-17 49 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。否則,很容易發生意外丟失數據。