Home »
.Net »
C# Programs
C# program to convert a temperature from Celsius to Fahrenheit
Here, we are going to learn how to convert a temperature from Celsius to Fahrenheit in C#?
By Nidhi Last updated : April 15, 2023
Celsius to Fahrenheit Conversion C#
Here we will read the temperature in Celsius and then convert it into the corresponding Fahrenheit temperature.
C# code for Celsius to Fahrenheit conversion
The source code to convert a Celsius temperature into Fahrenheit is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//C# program to convert a Celsius temperature into Fahrenheit.
using System;
class Program
{
static double convertToFahrenheit(double celTemp)
{
double fTemp = 0;
fTemp = (celTemp * 9) / 5 + 32;
return fTemp;
}
static void Main(string[] args)
{
double celTemp=0;
double ferTemp=0;
Console.Write("Enter the value of temperature in Celsius(°C): ");
celTemp = double.Parse(Console.ReadLine());
ferTemp = convertToFahrenheit(celTemp);
Console.WriteLine("Fahrenheit temperature is(°F) : " + ferTemp);
}
}
Output
Enter the value of temperature in Celsius(°C): 32.5
Fahrenheit temperature is(°F) : 90.5
Press any key to continue . . .
Explanation
In the above program, we created a class Program that contains two static methods convertToFahrenheit() and Main(). The convertToFahrenheit() method is used to convert the Celsius temperature into Fahrenheit.
In the Main() method we read the value of temperature in Celsius and then convert the temperature into Fahrenheit using convertToFahrenheit() method() and print the result on the console screen.
C# Basic Programs »