ขั้นแรก ตั้งอุณหภูมิฟาเรนไฮต์ −
double fahrenheit = 97;
Console.WriteLine("Fahrenheit: " + fahrenheit); แปลงเป็นเซลเซียสตอนนี้ -
celsius = (fahrenheit - 32) * 5 / 9;
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อแปลงฟาเรนไฮต์เป็นเซลเซียสได้
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
class MyApplication {
static void Main(string[] args) {
double celsius;
double fahrenheit = 97;
Console.WriteLine("Fahrenheit: " + fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
Console.WriteLine("Celsius: " + celsius);
Console.ReadLine();
}
}
} ผลลัพธ์
Fahrenheit: 97 Celsius: 36.1111111111111