c# property setter body without declaring a class-level property variable

前端 未结 8 967
清歌不尽
清歌不尽 2021-01-11 17:38

Do I need to declare a class-level variable to hold a property, or can I just refer to self.{propertyname} in the getter/setter?

In other words, can I d

8条回答
  •  时光取名叫无心
    2021-01-11 18:38

    You should have a backing variable. Take a closer look:

    get { return this.mongoFormId; }
    

    Is going to call the getter on mongoFormId, which will call that code again, and again, and again! Defining a backing variable will avoid the infinite recursive call.

提交回复
热议问题