Skip to content

Instantly share code, notes, and snippets.

@lgolubyev
Created June 15, 2021 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgolubyev/788916d31bf205325610dbff62cdd253 to your computer and use it in GitHub Desktop.
Save lgolubyev/788916d31bf205325610dbff62cdd253 to your computer and use it in GitHub Desktop.
class Temperature
{
public float Degrees { get; set; }
}
class Celsius : Temperature
{
public Celsius(float temp)
{
Grados = temp;
}
public static implicit operator Fahrenheit(Celsius c)
{
return new Fahrenheit((9.0f / 5.0f) * c.Degrees + 32);
}
}
class Fahrenheit : Temperature
{
public Fahrenheit(float temp)
{
Grados = temp;
}
public static implicit operator Celsius(Fahrenheit fahr)
{
return new Celsius((5.0f / 9.0f) * (fahr.Degrees - 32));
}
}
Celsius cel = new Celsius(10);
Fahrenheit far = cel;
Celsius cel2 = far;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment