In c# when I always heard that is a good practice when creating a property for a class to include the get e set functions. For example:
public int Id { get; set; }
I think the reason to be a good practice is that if I want to change the behaviour I do not need to change the public interface of my class. Example:
public int Id
{
get;
set
{
if (value < 0)
value = 0;
}
}
My question is, if I declare my property without the get and set methods I will not get the same effect? If I declare my property like this:
public int Count;
Can I change is behaviour without change the public interface? If I get the same effect then what’s the point of creating the get and set methods by default if in 90% of the time we don’t need them?