while loop returning same date value even after adding a day each time - c# -
this question has answer here:
- datetime.adddays() not working expected 2 answers
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
Post a Comment