Created
June 15, 2021 11:56
-
-
Save lgolubyev/788916d31bf205325610dbff62cdd253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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