+ 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 */ }

16th Oct 2017, 4:23 PM
Pablo Casado Rodríguez
Pablo Casado Rodríguez - avatar
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) { }
21st Sep 2019, 2:09 PM
Shreyas Patel
Shreyas Patel - avatar
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).
29th Jan 2022, 10:19 AM
Rishi Kaushik
Rishi Kaushik - avatar