我已經看到了某種形式的這前一段時間,但我不記得這是什麼所謂,因此對如何實現這樣的事情沒有任何線索:這個語法叫什麼? 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。