C# Properties Get and Set
My son is learning to program. Last week he asked me to explain C# properties get and set and, as it turns out, it looks like many others are asking for the same. So, I’ve decided to spend the time on this post, explaining getters and setters in about as much detail as one can expect.
So here it goes…
Member Variables
So, a class has "member variables" that are typically scoped as private, although they could be (but shouldn’t be) scoped as public.
class SomeClass
{
private int _someMemberIntegerVariable;
}
Inside the class definition but not in the methods. You’ll also sometimes see this referred to as a “field”. I call them “member variables” because that is what I learned them as back when I was programming C++.
Local Variables
If the variable is in a method, it is called a "local variable"
class SomeClass
{
public void SomeMethod()
{
int someLocalIntegerVariable;
}
}
Class “State”
Now, the reason we have member variables is because they hold the "state"
Comments