c# - Boundaries in Classes -
this may silly question when create class how supposed set boundaries of properties in it.
example: if have class
class product { private string name; public string name { { return name; } set { name = value; } } private int quantity; public int quantity { { return quantity; } set { quantity = value; } } } how supposed limit quantity 0 or higher
edit: quick response difference between 2 answers. see both same thing way better used?
edit: how can set 2 boundaries example - if want quantity between 0 , 120?
private int quantity; public int quantity { { return quantity; } set { if (value < 0 || value>120) throw new argumentoutofrangeexception(); else quantity = value; } }
Comments
Post a Comment