Created
September 16, 2016 22:50
-
-
Save saamerm/5bd5788e8fb14d38afad2eb5a5872b8d to your computer and use it in GitHub Desktop.
"Encapsulation"-Notes on getter and setter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Getter or Accessor ethod (Setter methodd is also called Mutator) | |
namespace Testing | |
{ | |
public class SomeClass | |
{ | |
private int someVariable; | |
public int getSomeVariable(){ | |
return someVariable; | |
} | |
} | |
public class ANotherCLass | |
{ | |
public void method() | |
{ | |
Console.WriteLine(new SomeClass().getSomeVariable()); | |
} | |
} | |
} | |
_____________________________________ | |
Short form | |
namespace Testing | |
{ | |
public class SomeClass | |
{ | |
int someVariable{get;} | |
} | |
public class ANotherCLass | |
{ | |
public void method() | |
{ | |
Console.WriteLine(new SomeClass().getSomeVariable()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment