I have 2 static variables like below
private static DateTime _currentPollStartDate = DateTime.MinValue; //As Default
private static DateTime _currentPollEndDate = DateTime.MinValue; //As Default
In a method, I try to set the values:
public void ProcessItems()
{
var Items = GetItems();
//In here, it reaches inside
if (Items.HasItems)
{
//Items[0].PollStartDate.HasValue is TRUE
//I can NOT set either Items[0].PollStartDate.Value or DateTime.MaxValue
_currentPollStartDate = Items[0].PollStartDate.HasValue ? Items[0].PollStartDate.Value : DateTime.MaxValue;
//Items[0].PollEndDate.HasValue is TRUE
//I can NOT set either Items[0].PollEndDate.Value or DateTime.MaxValue
_currentPollEndDate = Items[0].PollEndDate.HasValue ? Items[0].PollEndDate.Value : DateTime.MaxValue;
}
//...
}
But when I do this with IF
I don't have the problem as stated above, why?
public void ProcessItems()
{
var Items = GetItems();
//In here, it reaches inside
if (Items.HasItems)
{
if (Items[0].PollStartDate.HasValue)
_currentPollStartDate = Items[0].PollStartDate.Value;
if (Items[0].PollEndDate.HasValue)
_currentPollEndDate = Items[0].PollEndDate.Value;
}
//...
}
Also, when I declare the variables not static
this also solves my problem even though I use it like in my first code. But why can't I use both static
and if statement
as in my first code?
Edit: Expected Value: something like _currentPollStartDate -> 2013-04-18 10:03:03
Result Value: _currentPollStartDate -> 0001-01-01 00:00:00 (This is not even MAX value)