我有这个代码:
Console.Write("Red = ");
var input = Console.ReadLine();
if (!Double.TryParse(input, out red))
{
Console.WriteLine("You have not entered an appropriate value!");
}
Console.Write("Green = ");
input = Console.ReadLine();
if (!Double.TryParse(input, out green))
{
Console.WriteLine("You have not entered an appropriate value!");
}
Console.Write("Green = ");
input = Console.ReadLine();
if (!Double.TryParse(input, out green))
{
Console.WriteLine("You have not entered an appropriate value!");
}
我想更换相同的零件。
我创建了班级
public class ConverNumber
{
public string InputString { get; private set; }
public double Number { get; private set; }
public static void ConvertNumber(string inputString, out double number)
{
if (!Double.TryParse(inputString, out number))
{
Console.WriteLine("You have not entered an appropriate value!");
}
}
}
但我不明白如何使用它?
而且我不确定也许我应该创建一个方法?