- class bird
- {
- private int var = 12;
- public int Value
- {
- set
- {
- var = value;
- }
- get
- {
- return Value;//注意这里,返回的是Value,会产生递归
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- bird bd = new bird();
- Console.WriteLine("{0}",bd.Value);//注意这里
- System.Threading.Thread.Sleep(10000);
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/2209201513727.html
来源: http://www.codesnippet.cn/detail/2209201513727.html