一段随心而发的代码
public class CodingFarmer { private double _pay; private double _yearAdd; public double Pay { get { return _pay/2; } set { _pay = value*2; } } public double YearAdd { get { if (0 < _yearAdd) return _yearAdd; throw new Exception("You despise my IQ or you shouldn't have a girlfriend forever"); } set { _yearAdd = value*3; } } public double GetPay() { return _pay; } public double GetYearAdd() { return _yearAdd-40000; } } public class BeautifulGirl { public double Pay { get; set; } public double YearAdd { get; set; } } class Program { static void Main(string[] args) { var you = new BeautifulGirl(); you.Pay = 50000; you.YearAdd = 20000; var me = new CodingFarmer(); me.Pay = you.Pay; me.YearAdd = you.YearAdd; // Console.WriteLine(me.YearAdd); Console.WriteLine("Now your pay is "+you.Pay+" and every year add "+you.YearAdd); Console.WriteLine("Now my pay is "+me.GetPay()+" and every year add "+me.GetYearAdd()); Console.ReadLine(); } }
猜猜结果。