Properties vs Methods

后端 未结 16 1947
傲寒
傲寒 2020-11-22 08:23

Quick question: When do you decide to use properties (in C#) and when do you decide to use methods?

We are busy having this debate and have found some areas where it

16条回答
  •  死守一世寂寞
    2020-11-22 08:51

    I come from java an i used get.. set.. method for a while.

    When i write code, i don't ask to my self: "accessing this data is simple or require a heavy process?" because things can change (today retrive this property is simple, tomonrow can require some or heavy process).

    Today i have a method SetAge(int age) tomonrow i will have also method SetAge(date birthdate) that calculate the age using the birthdate.

    I was very disappointed that the compiler transform property in get and set but don't consider my Get... and Set.. methods as the same.

提交回复
热议问题