Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a hangover from languages where values are implicitly converted to a boolean type.</p> <p>For the most part, anything that was non-<code>null</code> or non-<code>0</code> would be treated as <code>true</code>, otherwise it was equivalent to <code>false</code>. This meant that any assignation of a constant would always be <code>true</code>.</p> <p>This thing to remember here is that <strong>the assignment function returns the value assigned</strong>, much in the same way that <code>5</code> is the result of <code>2+3</code>, <code>myInt = 5</code> also returns <code>5</code>.</p> <p>Because of this, it was recommended that you check the variable <em>against</em> the constant. The <code>null</code> example is actually probably a bit contrived in this case, as it would, in most languages, return as false.</p> <p>As an example:</p> <pre><code>if(i = 1) { printf("Always out\n"); } else { printf("Never prints\n"); } </code></pre> <p><code>i</code> is assigned the value of <code>1</code>, which then returns the value of the assignment, <code>1</code>, to the <code>if</code> statement. This is equivalent to <code>true</code>, and the <code>if</code> condition matches.</p> <p>If you were to attempt to assign <code>i</code> to the constant <code>1</code>, you wouldn't compile, and so it was recommended that you do things it that order (e.g. <code>1 == i</code>).</p> <p>This is not neccesary in C#, and further to your example, the recommended practice is to call <code>if(String.IsNullOrEmpty(myStringValue)) { //.... }</code>, as a string has... two ... default values from a semantic perspective.</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. 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