using System;
namespace Recetas.Ch01
{
public class Celsius
{
public float Grados
{
get
{
return grados;
}
}
private float grados;
public Celsius(float temperatura)
{
grados = temperatura;
}
///
/// Conversión explícita de Celsius a Fahrenheit
///
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;
}
///
/// Conversión explícita de Fahrenheit a Celsius
///
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();
}
}
}