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

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -