Convert Fahrenheit and Celsius

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
C# Code Snippets

C# Source Code Bank

See also …
edit

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

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;
}

Personal tools