Created
August 6, 2017 21:56
-
-
Save fernandezjose/588b1b73e4e211bec495af70dcd44a41 to your computer and use it in GitHub Desktop.
This file contains 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; | |
namespace OperadoresImplicitos | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Futbolista cristiano = "Cristiano Ronaldo"; | |
cristiano.Goles = 20; | |
int golesPorCristiano = cristiano; | |
string nombreDelGoleador = cristiano; | |
Console.WriteLine($"El goleador se llama {nombreDelGoleador} y tiene {golesPorCristiano} goles anotados"); | |
Console.ReadKey(); | |
} | |
} | |
class Futbolista | |
{ | |
public string Nombre { get; set; } | |
public int Goles { get; set; } | |
public Futbolista(string nombre) | |
{ | |
this.Nombre = nombre; | |
} | |
public static implicit operator Futbolista(string valor) | |
{ | |
var f = new Futbolista(valor); | |
return f; | |
} | |
public static implicit operator string(Futbolista f) | |
{ | |
return f.Nombre; | |
} | |
public static implicit operator int(Futbolista f) | |
{ | |
return f.Goles; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment