c# - Add Days methods -


i have create class includes 3 methods.
1st - shows current date
2nd - current date + 7days
3rd - current date - 7days.

i had dealing dates in c # created sth :

    public class date     {         private datetime date = datetime.now;           public  datetime now()         {             return date;          }         public  datetime aktuplusone ()         {             datetime date = datetime.now.adddays(7);             return date;         }          public datetime aktuminusone()         {             datetime date = datetime.now.adddays(-7);             return date;          }     } 

is ok or not ? works fine, care habits .

no need create additional method framework provides functionality out of box datetime.now.adddays(numberofdays). however, if want create generic method requirement, create 1 instead of 3 methods.

public  datetime adddaystotoday(int days) {     return datetime.now.adddays(days); }  datetime today = adddaystotoday(0); datetime todayplusseven = adddaystotoday(7); datetime todayminusseven = adddaystotoday(-7); 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -