# Converting Celsius to Fahrenheit in C#: A Comprehensive Guide

Temperature conversion between Celsius and Fahrenheit is a commonly used calculation in various fields including science and engineering. In this article, we will learn how to convert Celsius to Fahrenheit in C# and also how to convert Fahrenheit to Celsius using C# programming language.

## Celsius to Fahrenheit Conversion Formula

The formula for converting Celsius to Fahrenheit is straightforward:
`F = C * 9/5 + 32`
where F is the temperature in Fahrenheit and C is the temperature in Celsius.

### Code Example: Celsius to Fahrenheit Conversion

The following is a code example that demonstrates how to convert Celsius to Fahrenheit in C#.

```using System;

namespace CelsiusToFahrenheitConversion
{
class Program
{
static void Main(string[] args)
{
double celsius;
double fahrenheit;

Console.WriteLine("Enter the temperature in Celsius: ");

fahrenheit = celsius * 9 / 5 + 32;

Console.WriteLine("Temperature in Fahrenheit: " + fahrenheit);
}
}
}
```

Output:

#### Code Explanation:

In the above code, we first declare two variables celsius and fahrenheit to store the temperature in Celsius and Fahrenheit respectively. Then, we use the `Console.ReadLine()` method to read the temperature in Celsius from the user.
Next, we use the conversion formula to convert the temperature from Celsius to Fahrenheit:

fahrenheit = celsius * 9 / 5 + 32. Finally, we display the temperature in Fahrenheit using the `Console.WriteLine()` method.

## Fahrenheit to Celsius Conversion Formula

The formula for converting Fahrenheit to Celsius is:
`C = (F - 32) * 5/9`
where F is the temperature in Fahrenheit and C is the temperature in Celsius.

### Code Example: Fahrenheit to Celsius Conversion

The following is a code example that demonstrates how to convert Fahrenheit to Celsius in C#.

```using System;

namespace FahrenheitToCelsiusConversion
{
class Program
{
static void Main(string[] args)
{
double fahrenheit;
double celsius;

Console.WriteLine("Enter the temperature in Fahrenheit: ");

celsius = (fahrenheit - 32) * 5 / 9;

Console.WriteLine("Temperature in Celsius: " + celsius);
}
}
}
```

Output:

```Enter the temperature in Fahrenheit:
95
Temperature in Celsius: 35
```

#### Code Explanation:

In the above code, we first declare two variables `fahrenheit` and `celsius` to store the temperature in Fahrenheit and Celsius respectively. Then, we use the `Console.ReadLine()` method to read the temperature in Fahrenheit from the user.
Next, we use the conversion formula to convert the temperature from Fahrenheit to Celsius:

celsius = (fahrenheit – 32) * 5 / 9. Finally, we display the temperature in Celsius using the `Console.WriteLine() `method.

## What is 180 Celsius in Fahrenheit?

To convert 180 Celsius to Fahrenheit, we can use the conversion formula:
`F = C * 9/5 + 32`

Where F is the temperature in Fahrenheit and C is the temperature in Celsius. Putting the value 180 for C, we will get:

F = 180 * 9/5 + 32
F = 324

So, 180 Celsius is equal to 324 Fahrenheit.

## Conclusion:

In this article, we have covered the basics of converting temperatures between Celsius and Fahrenheit in C#. We have learned the conversion formulas and provided code examples and explanations for both Celsius to Fahrenheit and Fahrenheit to Celsius conversions. With this knowledge, you should be able to easily implement temperature conversions in your C# projects.

## FAQs

### Q: What is the formula to convert Celsius to Fahrenheit in C#?

The formula to convert Celsius to Fahrenheit is F = C * 9/5 + 32, where F is the temperature in Fahrenheit and C is the temperature in Celsius.

### Q: How to convert Fahrenheit to Celsius in C#?

To convert Fahrenheit to Celsius in C#, We can use the formula C = (F – 32) * 5/9, where F is the temperature in Fahrenheit and C is the temperature in Celsius. We have provided a code example and explanation in this article for converting Fahrenheit to Celsius in C#.

### Q: Can you convert temperatures in other programming languages besides C#?

Yes, the formulas for converting temperatures between Celsius and Fahrenheit are the same in any programming language. You can implement these formulas in any programming language of your choice.

### Q: Why is it important to know how to convert temperatures in programming?

Converting temperatures is a commonly used calculation in many fields. Knowing how to convert temperatures in programming can be useful for various projects and applications that require temperature conversions. Additionally, it helps improve your programming skills and knowledge.

References: Tutorialspoint- Celsius to Fahrenheit

Articles you might also like: 