S
shapper
Hello,
I have a class property as follows:
public string UnitPrice { get; set; }
But when I need to implement some validation logic, according to some
documentation I have the following:
public double UnitPrice {
get {
return _unitPrice;
}
set {
if (value >= 0.00) {
_unitPrice = value;
}
_errors.Add("UnitPrice", value + " is not valid. The unit
price must be larger than 0.00.");
}
}
double _unitPrice;
My questions are:
- Why the _unitPrice? Does the property needs this extra variable?
- And do I need to add the return _unitPrice in get even if it doing
exactly the same as in:
public string UnitPrice { get; set; }
Thanks,
Miguel
I have a class property as follows:
public string UnitPrice { get; set; }
But when I need to implement some validation logic, according to some
documentation I have the following:
public double UnitPrice {
get {
return _unitPrice;
}
set {
if (value >= 0.00) {
_unitPrice = value;
}
_errors.Add("UnitPrice", value + " is not valid. The unit
price must be larger than 0.00.");
}
}
double _unitPrice;
My questions are:
- Why the _unitPrice? Does the property needs this extra variable?
- And do I need to add the return _unitPrice in get even if it doing
exactly the same as in:
public string UnitPrice { get; set; }
Thanks,
Miguel