I assume this could be improved some how. VB.NET version:
Public MustInherit Class Degrees
Public Property val As Decimal
End Class
Public Class DegFahrenheit
Inherits Degrees
Public Sub New(ByVal deg As Decimal)
Me.val = deg
End Sub
Public Sub New(ByVal degCel As DegCelsius)
Me.val = degCel.val * 9 / 5 + 32
End Sub
Public Shared Widening Operator CType(ByVal Celsius As DegCelsius) As DegFahrenheit
Return New DegFahrenheit(Celsius)
End Operator
End Class
Public Class DegCelsius
Inherits Degrees
Public Sub New(ByVal deg As Decimal)
Me.val = deg
End Sub
Public Sub New(ByVal fahrenheit As DegFahrenheit)
Me.val = (fahrenheit.val - 32) * 5 / 9
End Sub
Public Shared Widening Operator CType(ByVal Farenheit As DegFahrenheit) As DegCelsius
Return New DegCelsius(Farenheit)
End Operator
End Class
For Testing:
Dim Input = New DegFahrenheit(68) 'Val = 68
Dim Celsius As DegCelsius = Input 'Val = 20
Dim Fahrenheit As DegFahrenheit = Celsius 'Val = 68
And as an unnecessary addition, which I would want for debugging add this to the Degrees class so that the value will display in the locals with no need to expand:
Public Overrides Function ToString() As String
Return val
End Function