Wrong Code In C# Via CLR Book
<p>I am reading this book and am stuck here:</p>

<pre><code>public static class EventArgExtensions { 
   public static void Raise&lt;TEventArgs&gt;(this TEventArgs e,  
      Object sender, ref EventHandler&lt;TEventArgs&gt; eventDelegate)  
      where TEventArgs : EventArgs { 

      // Copy a reference to the delegate field now into a temporary field for thread safety  
      EventHandler&lt;TEventArgs&gt; temp =  
         Interlocked.CompareExchange(ref eventDelegate, null, null); 

      // If any methods registered interest with our event, notify them   
      if (temp ! = null) temp(sender, e); 
   } 
}
</code></pre>

<p>Specifically the MSDN doc says that </p>

<blockquote>
<pre><code>public static object CompareExchange(ref object location1, object value, object comparand)
</code></pre>
  
  <p>Member of System.Threading.Interlocked</p>
  
  <p><strong>Summary:</strong><br>
  Compares two objects for reference equality and, if they are equal, replaces one of the objects.  </p>
  
  <p><strong>Parameters:</strong><br>
  <em>location1</em>: The destination object that is compared with comparand and possibly replaced.<br>
  <em>value</em>: The object that replaces the destination object if the comparison results in equality.<br>
  <em>comparand</em>: The object that is compared to the object at location1.  </p>
  
  <p><strong>Returns:</strong><br>
  The original value in location1.  </p>
  
  <p><strong>Exceptions:</strong><br>
  System.ArgumentNullException: The address of location1 is a null pointer.  </p>
</blockquote>

<p>which means that this is wrong : </p>

<pre><code> EventHandler&lt;TEventArgs&gt; temp =  
             Interlocked.CompareExchange(ref eventDelegate, null, null); 

          // If any methods registered interest with our event, notify them   
          if (temp ! = null) temp(sender, e); 
</code></pre>

<p>because I need to be checking what was <strong>passed</strong> in to CompareExchange and not the output.</p>

<p>Am I missing something?</p>
