When to use get; set; in c#

前端 未结 9 1197
庸人自扰
庸人自扰 2020-12-29 20:59

I\'m failing to understand what the difference is between initializing a variable, getting its value like this:

 //define a local variable.
   int i;

   i=          


        
9条回答
  •  轮回少年
    2020-12-29 21:28

    If you think you might need a more complicated getter or setter later, the automatic property syntax lets you upgrade without recompiling all callers. Moving from a field (member variable) to a property is a breaking change, however.

    Eric Lippert addresses the topic. Twice.

提交回复
热议问题