forum

home / developersection / forums / how important is it to use a variable for datetime.today when concerned about performance?

How important is it to use a variable for DateTime.Today when concerned about performance?

Anonymous User 2339 06-Apr-2013
Hi All!

It was in response to a post that contained the code:

var first = 
    new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMonths(-1);
var last = 
    new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddDays(-1);
If I am looking to improve performance, how important is it to store DateTime.Today in a variable instead of calling it multiple times? And roughly how many uses of DateTime.Today would justify creating a variable for it?

Edit: I realize I should test my program to see if there are performance problems first before worrying about something as trivial as this. For the sake of this question, assume that I have already done this and determined that additional optimization is needed.

Thanks in advance!


c# c# 
Updated on 06-Apr-2013

I am a content writter !


Message
Can you answer this question?

Answer

1 Answers

Liked By