C#怎么处理从屏幕读入数值
我想要从屏幕中读取0.02这个值,然后用于运算后输出。怎么办呢 我想用Console.Read(),但是只能读入字符,怎么转换呢
c#
------解决方案--------------------string str=Console.ReadLine();//输入0.02
double myDouble=Convert.ToDouble(str);
------解决方案--------------------using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("请输入myDouble:");
string str1 = Console.ReadLine();//输入0.02
Console.WriteLine("请输入bitrate:");
string str2 = Console.ReadLine();//
double myDouble = Convert.ToDouble(str1);
double bitrate = Convert.ToDouble(str2);
double result = bitrate * (1.0 + myDouble);
Console.WriteLine("计算结果:{0}",result);
}
catch (Exception err)
{
Console.WriteLine("错误:" + err.Message);
}
finally
{
Console.ReadKey();
}
}
}
}
完整代码了