클래스의 변수를 선언 할 샘플 코드가 있지만 메서드에서 사용하면 값이 0이됩니다. 자세한 내용은 아래 코드를 참조하십시오. 당신이 변수 값을 초기화하지 않았다 beacuse클래스에서 선언 된 변수를 초기화하는 방법
디스플레이 방법 내부class RectangleExample
{
double i;
double j;
public void GetValues()
{
i = 2.5;
j = 3.5;
}
public double GetArea()
{
return i * j;
}
public void Display()
{
Console.WriteLine("Length: {0}", i);
Console.WriteLine("width: {0}", j);
Console.WriteLine("Area: {0}", GetArea());
}
}
class ExecuteRectangle
{
static void Main(string[] args)
{
RectangleExample obj1 = new RectangleExample();
obj1.Display();
Console.ReadKey();
}
}
공유 코드. –
* "아래 코드를 찾으십시오."* 찾을 수 없습니다 ... 어디에서 숨기셨습니까? –
생성자에 대해 들었습니까? :) – C1sc0