Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>First Question:</strong></p> <p>A <code>|</code> does a bitwise or; a bit will be set in the result if it is set in the first value or the second value. (You use it on <code>enums</code> to create values that are combinations of other values) If you were to use a bitwise and, it wouldn't make very much sense.</p> <p>It gets used as follows:</p> <pre><code>[Flags] enum FileAccess{ None = 0, // 00000000 Nothing is set Read = 1, // 00000001 The read bit (bit 0) is set Write = 2, // 00000010 The write bit (bit 1) is set Execute = 4, // 00000100 The exec bit (bit 2) is set // ... ReadWrite = Read | Write // 00000011 Both read and write (bits 0 and 1) are set // badValue = Read &amp; Write // 00000000 Nothing is set, doesn't make sense ReadExecute = Read | Execute // 00000101 Both read and exec (bits 0 and 2) are set } // Note that the non-combined values are powers of two, \ // meaning each sets only a single bit // ... // Test to see if access includes Read privileges: if((access &amp; FileAccess.Read) == FileAccess.Read) </code></pre> <p>Essentially, you can test if certain bits in an <code>enum</code> are set; in this case we are testing to see if the bits corresponding to a <code>Read</code> are set. Values <code>Read</code> and <code>ReadWrite</code> would both pass this test (the both have bit zero set); <code>Write</code> would not (it does not have bit zero set).</p> <pre><code>// if access is FileAccess.Read access &amp; FileAccess.Read == FileAccess.Read // 00000001 &amp; 00000001 =&gt; 00000001 // if access is FileAccess.ReadWrite access &amp; FileAccess.Read == FileAccess.Read // 00000011 &amp; 00000001 =&gt; 00000001 // uf access is FileAccess.Write access &amp; FileAccess.Read != FileAccess.Read // 00000010 &amp; 00000001 =&gt; 00000000 </code></pre> <p><strong>Second Question:</strong></p> <p>I think when you say "and/or", you mean "one, the other or both". This is exactly what the <code>||</code> (or operator) does. To say "one or the other, but not both", you'd use <code>^</code> ( the exclusive or opertor).</p> <p>Truth tables (true==1, false==0):</p> <pre><code> A B | A || B ------|------- OR 0 0 | 0 0 1 | 1 1 0 | 1 1 1 | 1 (result is true if any are true) A B | A ^ B ------|------- XOR 0 0 | 0 0 1 | 1 1 0 | 1 1 1 | 0 (if both are true, result is false) </code></pre>
    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.
    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