Skip to content

Instantly share code, notes, and snippets.

@fernandezjose
Created August 6, 2017 21:56
Show Gist options
  • Save fernandezjose/588b1b73e4e211bec495af70dcd44a41 to your computer and use it in GitHub Desktop.
Save fernandezjose/588b1b73e4e211bec495af70dcd44a41 to your computer and use it in GitHub Desktop.
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