这是我第一次使用这个论坛!我是一名大学二年级学生,刚刚开始用 C# 编写代码(就像我们去年做 java 一样)。
其中一个实验练习是编写一个小程序,它会弹出一个终端窗口,要求输入一个数字(十进制数),这意味着程序通过调用另一个类的方法来计算面积的半径!
我已经在 Visual Studio 2008 中编写了代码,使用相同的命名空间,它可以构建并运行但不起作用?这是具有不同类的代码,任何帮助/建议将不胜感激。
编码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program4
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter The Radius:");//Text to be displayed in the console
Console.ReadLine();//Read the line and store information in temp directory
Pie one = new Pie();//Calls the method from the class in the same namespace
Console.ReadKey();//Reads and displays the next key pressed in the console
Environment.Exit(0);//Exit the Enviromet
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program4
{
class Pie
{
public void Pin ()
{
int r;//defining the value that is going to be entered as an integer
double result;//declaring the result string as a double
r = (int)Convert.ToDouble(Console.ReadLine());
result=(3.14*r*r);//the calculation to work out pie
Console.WriteLine("The Radius of the circle is " + (result));//the writeline statement
}
}
}