You simply throw
an exception in the set
:
private int someProperty;
public int SomeProperty {
get { return someProperty; }
set {
if((value % 3) != 0) throw new ArgumentOutOfRangeException(
"the value must be divisible by 3");
someProperty = value;
}
}
Produces: