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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -