Visual c#.net

来源:百度知道 编辑:UC知道 时间:2024/06/05 21:58:23
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double r, s, c;
r = Console.Read();
s = 3.14 * r * r;
c = 2 * 3.14 * r;
Console.WriteLine("s={0}\nc={1}\n", s, c);

}
}
}

哪错了???

Console.ReadLine()命令是提示用户输入一个字符串,也就是string类型数据。
你把string类型赋给了double类型的变量,这里是通不过的,需要进行数据类型转换。
比如一楼的double.Parse(Console.ReadLine())方法就可以做到。

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double r, s, c;
r = double.Parse(Console.ReadLine());
s = 3.14 * r * r;
c = 2 * 3.14 * r;
Console.WriteLine("s={0}\nc={1}\n", s, c);
Console.ReadKey();
}
}
}

r = Console.ReadLine();