+ 2
Is the comparison of time and null in the if statement below valid or not? Why or why not?
static DateTime time; /* ... */ if (time == null) { /* do something */ }
2 odpowiedzi
+ 1
If you take a time pointer and initialize it with null then it will be useful to compare with null incase you are getting time from other source. Ex.
DateTime *time = Null;
GetTime(time);
If(time == null)
{
}
0
static DateTime time; /* ... */ if (time == null) { /* do something */ }
Here If statement is valid, and it return result as false. Because DateTime variable can never be null (it is automatically initialized to 1/1/0001 12:00:00 AM).