C#???(static)
???????????? ???????[ 2013/7/23 11:32:19 ] ????????
??????t????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? System ????????е? Math ?????????????????
??????????
?????????д???????????????????????е???????????Ρ?????????????????????????κ??????????????????????????????????????κ??????????????????????????????????????κ?????????????????????????????????????仯??????????
???????磬???????????????????????????????????? ??????????????????????????д?? ?????????????????? static ???????????????????????磺
public class Automobile
{
public static int NumberOfWheels = 4;
public static int SizeOfGasTank
{
get
{
return 15;
}
}
public static void Drive() { }
public static event EventType RunOutOfGas;
//other non-static fields and properties...
}
???????????????α??????????????κξ????????????????????????????????????????????????????????????????????ó????λ?á????磺
Automobile.Drive();
int i = Automobile.NumberOfWheels;
??????? ??????????????????????????????????????????????????????????????????
public static class TemperatureConverter
{
public static double CelsiusToFahrenheit(string temperatureCelsius)
{
// Convert argument to double for calculations.
double celsius = System.Double.Parse(temperatureCelsius);
// Convert Celsius to Fahrenheit.
double fahrenheit = (celsius * 9 / 5) + 32; return fahrenheit;
}
public static double FahrenheitToCelsius(string temperatureFahrenheit)
{
// Convert argument to double for calculations.
double fahrenheit = System.Double.Parse(temperatureFahrenheit);
// Convert Fahrenheit to Celsius.
double celsius = (fahrenheit - 32) * 5 / 9;
return celsius;
}
}
class TestTemperatureConverter
{
static void Main()
{
System.Console.WriteLine("Please select the convertor direction");
System.Console.WriteLine("1. From Celsius to Fahrenheit.");
System.Console.WriteLine("2. From Fahrenheit to Celsius.");
System.Console.Write(":");
string selection = System.Console.ReadLine();
double F?? C = 0;
switch (selection)
{
case "1":
System.Console.Write("Please enter the Celsius temperature: ");
F = TemperatureConverter.CelsiusToFahrenheit(System.Console.ReadLine());
System.Console.WriteLine("Temperature in Fahrenheit: {0:F2}"?? F);
break;
case "2":
System.Console.Write("Please enter the Fahrenheit temperature: ");
C = TemperatureConverter.FahrenheitToCelsius(System.Console.ReadLine());
System.Console.WriteLine("Temperature in Celsius: {0:F2}"?? C);
break;
default:
System.Console.WriteLine("Please select a convertor.");
break;
}
}
}
????????
2
98.6
????????
Please select the convertor
1. From Celsius to Fahrenheit.
2. From Fahrenheit to Celsius.
:2
Please enter the Fahrenheit temperature: 98.6
Temperature in Celsius: 37.00
????????????????????????????
Please select the convertor
1. From Celsius to Fahrenheit.
2. From Fahrenheit to Celsius.
:1
Please enter the Celsius temperature: 37.00
Temperature in Fahrenheit: 98.60
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11