初めてこのフォーラムを利用しました!私は大学 2 年生で、C# でコードを書き始めたばかりです (昨年は Java をやったように)。
ラボ演習の 1 つは、端末ウィンドウをポップアップ表示して数値 (10 進数) を要求する小さなプログラムを作成することです。これは、プログラムが別のクラスからメソッドを呼び出して面積を計算する半径を意味します。
同じ名前空間を使用して 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
}
}
}