Skip to content

Instantly share code, notes, and snippets.

@saamerm
Created September 16, 2016 22:50
Show Gist options
  • Save saamerm/5bd5788e8fb14d38afad2eb5a5872b8d to your computer and use it in GitHub Desktop.
Save saamerm/5bd5788e8fb14d38afad2eb5a5872b8d to your computer and use it in GitHub Desktop.
"Encapsulation"-Notes on getter and setter
//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