using System;
namespace Recetas.Ch01
{
public class Celsius
{
public float Grados
{
get
{
return grados;
}
}
private float grados;
public Celsius(float temperatura)
{
grados = temperatura;
}
///<summary>
/// Conversión explícita de Celsius a Fahrenheit
///</summary>
public static explicit operator Fahrenheit(Celsius c)
{
return new Fahrenheit((9.0f/5.0f)*c.grados + 32);
}
}
public class Fahrenheit
{
public float Grados
{
get
{
return grados;
}
}
private float grados;
public Fahrenheit(float temperatura)
{
grados = temperatura;
}
///<summary>
/// Conversión explícita de Fahrenheit a Celsius
///</summary>
public static explicit operator Celsius(Fahrenheit fahr)
{
return new Celsius((5.0f/9.0f)*(fahr.grados - 32));
}
}
public class PruebaCelsiusFahrenheit
{
public static void Main()
{
Fahrenheit fahr = new Fahrenheit(100.0f);
Console.Write("{0} Fahrenheit", fahr.Grados);
Celsius c = (Celsius) fahr;
Console.Write(" = {0} Celsius", c.Grados);
Fahrenheit fahr2 = (Fahrenheit) c;
Console.WriteLine(" = {0} Fahrenheit", fahr2.Grados);
Console.WriteLine();
}
}
}
dXNpbmcgU3lzdGVtOwoKbmFtZXNwYWNlIFJlY2V0YXMuQ2gwMQp7CglwdWJsaWMgY2xhc3MgQ2Vsc2l1cwoJewoJCXB1YmxpYyBmbG9hdCBHcmFkb3MKCQl7CgkJCWdldAoJCQl7CgkJCQlyZXR1cm4gZ3JhZG9zOwoJCQl9CgkJfQoJCXByaXZhdGUgZmxvYXQgZ3JhZG9zOwoJCQoJCXB1YmxpYyBDZWxzaXVzKGZsb2F0IHRlbXBlcmF0dXJhKQoJCXsKCQkJZ3JhZG9zID0gdGVtcGVyYXR1cmE7CgkJfQoJCQoJCS8vLzxzdW1tYXJ5PgoJCS8vLyBDb252ZXJzacOzbiBleHBsw61jaXRhIGRlIENlbHNpdXMgYSBGYWhyZW5oZWl0CgkJLy8vPC9zdW1tYXJ5PgoJCXB1YmxpYyBzdGF0aWMgZXhwbGljaXQgb3BlcmF0b3IgRmFocmVuaGVpdChDZWxzaXVzIGMpCgkJewo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