using System;
namespace Recetas.Ch01
{
public class Digito
{
public double Valor
{
get;
set;
}
public Digito(double valor)
{
Valor = valor;
}
public static implicit operator double(Digito d)
{
return d.Valor;
}
public static implicit operator Digito(double d)
{
return new Digito(d);
}
}
public class ClienteDigito
{
public static void Main()
{
Digito dig1 = new Digito(13);
// Conversión implícita: invocación del operador "double"
double numero = dig1;
// Conversión implícita: invocación del operador "Digito"
Digito dig2 = 17;
Console.WriteLine("numero = {0} dig2 = {1}", numero, dig2.Valor);
Console.WriteLine();
}
}
}
dXNpbmcgU3lzdGVtOwoKbmFtZXNwYWNlIFJlY2V0YXMuQ2gwMQp7CglwdWJsaWMgY2xhc3MgRGlnaXRvCgl7CgkJcHVibGljIGRvdWJsZSBWYWxvcgoJCXsKCQkJZ2V0OwoJCQlzZXQ7CgkJfQoJCQoJCXB1YmxpYyBEaWdpdG8oZG91YmxlIHZhbG9yKQoJCXsKCQkJVmFsb3IgPSB2YWxvcjsKCQl9CgkJCgkJcHVibGljIHN0YXRpYyBpbXBsaWNpdCBvcGVyYXRvciBkb3VibGUoRGlnaXRvIGQpCgkJewoJCQlyZXR1cm4gZC5WYWxvcjsKCQl9CgkJCgkJcHVibGljIHN0YXRpYyBpbXBsaWNpdCBvcGVyYXRvciBEaWdpdG8oZG91YmxlIGQpCgkJewoJCQlyZXR1cm4gbmV3IERpZ2l0byhkKTsKCQl9Cgl9CgkKCXB1YmxpYyBjbGFzcyBDbGllbnRlRGlnaXRvCgl7CgkJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJCXsKCQkJRGlnaXRvIGRpZzEgPSBuZXcgRGlnaXRvKDEzKTsKCQkJCgkJCS8vIENvbnZlcnNpw7NuIGltcGzDrWNpdGE6IGludm9jYWNpw7NuIGRlbCBvcGVyYWRvciAiZG91YmxlIgoJCQlkb3VibGUgbnVtZXJvID0gZGlnMTsKCQkJCgkJCS8vIENvbnZlcnNpw7NuIGltcGzDrWNpdGE6IGludm9jYWNpw7NuIGRlbCBvcGVyYWRvciAiRGlnaXRvIgoJCQlEaWdpdG8gZGlnMiA9IDE3OwoJCQlDb25zb2xlLldyaXRlTGluZSgibnVtZXJvID0gezB9IGRpZzIgPSB7MX0iLCBudW1lcm8sIGRpZzIuVmFsb3IpOwoJCQkKCQkJQ29uc29sZS5Xcml0ZUxpbmUoKTsKCQl9Cgl9Cn0=