Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>VB.NET and C#.NET are different languages, built by different teams who have made different assumptions about usage; in this case the semantics of a NULL comparison.</p> <p>My personal preference is for the VB.NET semantics, which in essence gives NULL the semantics "I don't know yet". Then the comparison of 5 to "I don't know yet". is naturally "I don't know yet"; ie NULL. This has the additional advantage of mirroring the behaviour of NULL in (most if not all) SQL databases. This is also a more standard (than C#'s) interpretation of three-valued logic, as explained <a href="http://en.wikipedia.org/wiki/Three-valued_logic" rel="noreferrer">here</a>.</p> <p>The C# team made different assumptions about what NULL means, resulting in the behaviour difference you show. <a href="http://blogs.msdn.com/b/ericlippert/archive/2012/03/26/null-is-not-false.aspx" rel="noreferrer">Eric Lippert wrote a blog about the meaning of NULL in C#</a>. Per Eric Lippert: "I also wrote about the semantics of nulls in VB / VBScript and JScript <a href="http://blogs.msdn.com/b/ericlippert/archive/2003/09/30/53120.aspx" rel="noreferrer">here</a> and <a href="http://blogs.msdn.com/b/ericlippert/archive/2003/10/01/53128.aspx" rel="noreferrer">here</a>".</p> <p>In any environment in which NULL values are possible, it is imprtant to recognize that the Law of the Excluded Middle (ie that A or ~A is tautologically true) no longer can be relied on.</p> <p><strong>Update:</strong></p> <p>A <code>bool</code> (as opposed to a <code>bool?</code>) can only take the values TRUE and FALSE. However a language implementation of NULL must decide on how NULL propagates through expressions. In VB the expressions <code>5=null</code> and <code>5&lt;&gt;null</code> BOTH return false. In C#, of the comparable expressions <code>5==null</code> and <code>5!=null</code> only the <s>second</s> first <em>[updated 2014-03-02 - PG]</em> returns false. However, in ANY environment that supports null, it is incumbent on the programmer to know the truth tables and null-propagation used by that language.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload