我的程序抛出了以下异常:
System.StackOverflowException
当编译器执行设置属性时。
wine
类:
class wine
{
public int year;
public string name;
public static int no = 5;
public wine(int x, string y)
{
year = x;
name = y;
no++;
}
public int price
{
get
{
return no * 5;
}
set
{
price = value;
}
}
}
Program
类:
class Program
{
static void Main(string[] args)
{
wine w1 = new wine(1820, "Jack Daniels");
Console.WriteLine("price is " + w1.price);
w1.price = 90;
Console.WriteLine(w1.price);
Console.ReadLine();
}
}
private int _price
,然后将其设置为值,例如set { _price = value; }
。 - DGibbs