c# - Using properties for lists -


i'm trying use property prevent first value of list ever being less zero:

    private list<int> _mylist = new list<int>();     public list<int> mylist     {                 {             return _mylist;         }         set         {             if (value[0] < 0)             {                 value[0] = 0;             }              _mylist = value;         }     } 

add in code:

if(buttonpressed) {       mylist[0] -= 1; } 

however can press button , decrease value through zero.

what missing?

you never enter property, reserved setting value of actual list rather lists elements. best bet write method reduce items count

void adjustcount(int value) {     if(mylist[0] + value >= 0)         mylist[0] += value }   if(buttonpressed) {    adjustcount(-1); } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -