Value Proxy
[DebuggerDisplay("{value*100.0d}%")]
public struct Perceentage
{
private readonly double value;
public Perceentage(double value)
{
this.value = value;
}
public override string ToString()
{
return $"{value*100}%";
}
public static double operator *(double p1, Perceentage p2)
{
return p1 * p2.value;
}
public static Perceentage operator +(Perceentage p1, Perceentage p2)
{
return new Perceentage(p1.value+p2.value);
}
}
public static class ExtensitionPerceentage
{
public static Perceentage Percent(this int value)
{
return new Perceentage(value / 100.00d);
}
public static Perceentage Percent(this double value)
{
return new Perceentage(value / 100.00d);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(10d * 5.Percent());
Console.WriteLine(2.Percent() + 3.Percent());
}
}