I'm studying C #, quite a beginner, and I came across one thing, the course I'm doing has video lessons from 2015, and it passes me to create a class with attributes and properties this way: (Tabs and blank lines are my preference to "find me" in the code)
class ProgramaTeste {
protected int _numero;
public int numero {
set{ _numero = value; }
get{ return _numero; }
}
}
But in another question here on the site, I have been told that these statements are outdated and that I should use it this way:
class ProgramaTeste {
public int numero{ get; set: }
}
Sure enough it's optimized and better, but does not this compromise the encapsulation? For I am not declaring the variable as protected.