Getter and Setter in C# -
i'm playing around c# , i'm aksing myself proper method getter , setter. found google:
class myclass { button btnmybutton; // code... public button getbtnmybutton { { return btnmybutton; } } }
is there 'proper' way? or okay:
class myclass { button btnmybutton; // code... public button getbtnmybutton() { return this.btnmybutton; } }
whats difference?
as thomas mentioned, same things. may wonder point of getter
, setter
in case , it's syntactic sugar. however, means don't have create explicit field 1 created in background. therefore, can do
public button mybutton { get; private set; }
the private set;
ensures class can set value it's read-only outside classes. removing private
allow external classes write variable too.
Comments
Post a Comment