My program throws this exception:
System.StackOverflowException
when the compiler executes the set property.
The wine class:
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; } } } The Program class:
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 _priceand then set that to the value e.gset { _price = value; }