Search

Convert Fahrenheit and Celsius

This C# code snippet converts temperatures between the two major temperature scales—Fahrenheit and Celsius.
using System;

public static double CelsiusToFahrenheit 
   (string temperatureCelsius)
{
   double celsius = System.Double.Parse (temperatureCelsius);
   return (celsius * 9 / 5) + 32; 
}
 
public static double FahrenheitToCelsius 
   (string temperatureFahrenheit)
{
   double fahrenheit = System.Double.Parse (temperatureFahrenheit);
   return (fahrenheit - 32) * 5 / 9;
}