I have been trying to learn a bit more about delegates and lambdas while working on a small cooking project that involves temperature conversion as well as some cooking measurem
It sounds like you want something like:
Func celsiusToKelvin = x => x + 273.15m;
Func kelvinToCelsius = x => x - 273.15m;
Func fahrenheitToKelvin = x => ((x + 459.67m) * 5m) / 9m;
Func kelvinToFahrenheit = x => ((x * 9m) / 5m) - 459.67m;
However, you might want to consider not just using decimal
, but having a type which knows the units so you can't accidentally (say) apply the "Celsius to Kelvin" conversion to a non-Celsius value. Possibly have a look at the F# Units of Measure approach for inspiration.