I have seen some form of this some time ago, but I cannot recall what it was called, and therefore have no clue on how to implement something like this:
SomeMoneyFormat f = "€ 5,00";
Which calls some overload function that can parse the string into a SomeMoneyFormat
object.
When you do not specify that it should be cast it is an implicit cast
public static implicit operator SomeMoneyFormat(string d)
{
return new SomeMoneyFormat(d);
}
Then € 5,00
is passed as the string d
more about this here: http://msdn.microsoft.com/en-us/library/z5z9kes2(VS.71).aspx
Also, I can add that this should only be done when there is no risk of losing data. For example converting a double
to an int
will lose some precision, so it is an explicit cast
. Otherwise it would be easy to cast by accident and lose data.
Looks like an implicit type conversion to me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With