Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 917947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:17:34+00:00 2026-05-15T18:17:34+00:00

What is the reason null doesn’t evaluate to false in conditionals? I first thought

  • 0

What is the reason null doesn’t evaluate to false in conditionals?

I first thought about assignments to avoid the bug of using = instead of ==, but this could easily be disallowed by the compiler.

if (someClass = someValue) // cannot convert someClass to bool. Ok, nice

if (someClass) // Cannot convert someClass to bool. Why?

if (someClass != null) // More readable?

I think it’s fairly reasonable to assume that null means false. There are other languages that use this too, and I’ve not had a bug because of it.

Edit: And I’m of course referring to reference types.

A good comment by Daniel Earwicker on the assignment bug… This compiles without a warning because it evaluates to bool:

bool bool1 = false, bool2 = true;
if (bool1 = bool2)
{
    // oops... false == true, and bool1 became true...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:17:34+00:00Added an answer on May 15, 2026 at 6:17 pm

    It’s a specific design feature in the C# language: if statements accept only a bool.

    IIRC this is for safety: specifically, so that your first if (someClass = someValue) fails to compile.

    Edit: One benefit is that it makes the if (42 == i) convention (“yoda comparisons”) unnecessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the reason for this? I thought that if a pointer is null
For some reason, the first method doesn't display anything, while the second does: //Common
I have a TSQL SELECT that can return a null. I tried using ISNULL
Some of my code still uses malloc instead of new . The reason is
Here is the function I have now that obviously doesn't work. The reason it
I'm using CodeLite on Ubuntu and for some bizzare reason GCC keeps throwing this
I'm using the latest Asp.Net MVC version. For some reason, when my POST (Action
For whatever reason, ThreadPool 's QueueWorkItem doesn't return an IAsyncResult or some other handle
first off thank you for the pointer that something.endsWith doesn't do what i was
For some reason, the zlib.deflate filter doesn't seem to be working with socket pairs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.