The two code samples you gave are functionally equivalent right now, but the main reason for getter / setter methods (whether they're in the form of "properties" or explicit methods) is that their implementation can be changed without modifying the code that calls them. If you did that, these would not be equivalent, because the first one doesn't actually call the setter and the second one does. To match the second, the first constructor should be written as follows:
public test()
{
setTesting(false);
}
Or the second should be written to not call the setter, i.e. set the field instead of the property:
public test()
{
_isTesting = false;
}
private bool _isTesting;
public bool isTesting {
private set { _isTesting = value; }
get { return _isTesting; }
}
Other than that, there is no practical difference -- in most cases: Even though properties are essentially compiled into getter and setter methods anyway, they still retain metadata that they are in fact "properties" as opposed to "methods", and some APIs rely on this information.
The other difference is semantics: Properties are meant to be treated as if they are fields, implying that they do some kind of basic storage / retrieval from memory. If I see a method named GetX
as opposed to property X
in C# code, I'll probably assume that the method is doing something more advanced and treat it differently.