Skip to content

Instantly share code, notes, and snippets.

@angelobelchior
Created October 30, 2014 13:32
Show Gist options
  • Save angelobelchior/cebbc126414ef190973b to your computer and use it in GitHub Desktop.
Save angelobelchior/cebbc126414ef190973b to your computer and use it in GitHub Desktop.
Reescrita de Operador
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var p = 100 - 33.Percent();
Console.WriteLine(p);
Console.ReadLine();
}
}
#region Resolução
public class Percent
{
public float Value { get; set; }
public Percent(float value)
{
Value = value;
}
public static float operator -(float x, Percent y)
{
return x - CalcPercent(x, y);
}
public static float operator +(float x, Percent y)
{
return x + CalcPercent(x, y);
}
public static float operator *(float x, Percent y)
{
return x * CalcPercent(x, y);
}
public static float operator /(float x, Percent y)
{
return x / CalcPercent(x, y);
}
private static float CalcPercent(float x, Percent y)
{
return (x * (y.Value / 100));
}
}
public static class Methods
{
public static Percent Percent(this int self)
{
return new Percent(self);
}
}
#endregion Resolução
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment