System.StackOverflowException , when get set Properties are used?

前端 未结 3 2020
半阙折子戏
半阙折子戏 2021-01-01 19:45

An unhandled exception of type \'System.StackOverflowException\' occurred in wcfserviceLibrary.DLL

the code is show as follows.

[DataContract]
public         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-01 20:30

    You are referring to the property itself in the setter, so it will be calling itself recursively.(Over and over again until your stack overflows)

    By using the short hand notation with just get; and set;, you are basically adding an implied backing field (like a backing variable). This way your not triggering a recursive calls since your property is just a wrapper around the backing field.

提交回复
热议问题