我想写一个程序,有两个类,并从一个调用2个变量到另一个,但我有两个错误,说''Area.Circle'不包含定义'result1'“和”'Area.Circle'不包含'result2''的定义。我怎么解决这个问题?调用变量从不同的类c#
using System;
namespace Area
{
class Circle
{
public static void Area()
{
Console.WriteLine("Enter the radius of the first circle: ");
int r1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the radius of the second circle: ");
int r2 = Convert.ToInt32(Console.ReadLine());
double pi = Math.PI;
double result1 = pi * r1 * r1;
double result2 = pi * r2 * r2;
Console.WriteLine("The area of the first circle is {0}\nThe area of the second circle is {1}\n", result1, result2);
}
}
class Minimum
{
static void Main(string[] args)
{
Circle.Area();
Circle one = new Circle();
double min = Math.Min(Circle.result1, Circle.result2);
Console.WriteLine("min");
}
}
}
您在方法中定义了result1和result2。这意味着这些变量是该方法的本地变量,不能在其外部调用。如果你想保留这些变量,你需要在课程级别(在Circle内部但是在Area外部)声明它们。 – 2014-10-30 14:50:39