Created
October 30, 2014 13:32
-
-
Save angelobelchior/cebbc126414ef190973b to your computer and use it in GitHub Desktop.
Reescrita de Operador
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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