For money I am using a custom value type which holds only one decimal
field. Simplified code is as follows.
public struct Money
{
private decimal _value;
private Money(decimal money)
{
_value = Math.Round(money, 2, MidpointRounding.AwayFromZero);
}
public static implicit operator Money(decimal money)
{
return new Money(money);
}
public static explicit operator decimal(Money money)
{
return money._value;
}
}
While using this struct in my project sometimes an ambiguity arises. And also sometimes I am setting an object
with a constant number which is supposed to be a Money
. For now I am initializing the object like,
object myObject=(Money)200;
Can I assign a suffix for my custom type Money
. I'd like to initialize the object with the following.
object myObject=200p;
You can't assign custom suffixes with C#. The closest thing you can do is creating extension method for integers:
public static Money Para(this int value) // you can do same for decimals
{
return (Money)((decimal)value);
}
Usage:
var amount = 200.Para();
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