New Pop Quiz! Can (this == null) ever evaluate to true?

Say I have this bit of C# code:

if (this == null)
{
    Console.WriteLine("Null.");
}
else
{
    Console.WriteLine("Not null.");
}

Can the above ever produce the output “Null”?

(I happen to know the answer, which I will share in my next post. But I’ll let you puzzle over that one for now.)

Advertisements

One thought on “New Pop Quiz! Can (this == null) ever evaluate to true?

  1. This code produce the output “Null” when operator == has your own implementation and there is code which returns true in some cases.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: