To an external client that uses your code, it may not make much difference. But encapsulating your variables in a Property enables you to validate its value. For example, if there is an
Age
field, you can restrict its values betweeen 1 and 120 or so. Using public variables will not allow you to validate its values.
Here's an example:
int _age = 0;
public int Age {
get {
return _age;
}
set {
if (_age < 0 || _age > 120) {
throw new ArgumentException("Valid values for Age is between 0 and 120.");
}
_age = value;
}
}