while loop returning same date value even after adding a day each time - c# -


this question has answer here:

am doing silly here, fromdate value remains has been passed.

public list<string> getdates(datetime fromdate, datetime todate) {     list<string> dates = new list<string>();     while (fromdate <= todate)     {         dates.add(fromdate.toshortdatestring());         fromdate.adddays(1);     }     return dates; } 

i can't figure out why, please advise.

you need assign fromdate, adddays() not modify instance on called:

fromdate = fromdate.adddays(1); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -