Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save supreettare/47c0f2cfc86a2b0c0092ae03afcde969 to your computer and use it in GitHub Desktop.

Select an option

Save supreettare/47c0f2cfc86a2b0c0092ae03afcde969 to your computer and use it in GitHub Desktop.
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 */
}
@SaiSulochana
Copy link

if statement is not valid because datetime variable is value type.

@sajijohn80
Copy link

sajijohn80 commented Sep 19, 2017

The code will compile.
Equality (==) operator always returns false when one operand is null and the other is a Value type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment