title: Convert this delegate to an anonymous method or lambda
body: <p>I am new to all the anonymous features and need some help.  I have gotten the following to work:</p>
  
  <pre><code>public void FakeSaveWithMessage(Transaction t)
  {
      t.Message = "I drink goats blood";
  }
  
  public delegate void FakeSave(Transaction t);
  
  public void SampleTestFunction()
  {
      Expect.Call(delegate { _dao.Save(t); }).Do(new FakeSave(FakeSaveWithMessage));
  }
  </code></pre>
  
  <p>But this is totally ugly and I would like to have the inside of the Do to be an anonymous method or even a lambda if it is possible.  I tried:</p>
  
  <pre><code>Expect.Call(delegate { _dao.Save(t); }).Do(delegate(Transaction t2) { t2.Message = "I drink goats blood"; });
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Expect.Call(delegate { _dao.Save(t); }).Do(delegate { t.Message = "I drink goats blood"; });
  </code></pre>
  
  <p>but these give me</p>
  
  <blockquote>
    <p>Cannot convert anonymous method to type 'System.Delegate' because it is not a delegate type** compile errors.</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>
  
  <hr>
  
  <p>Because of what Mark Ingram posted, seems like the best answer, though nobody's explicitly said it, is to do this:</p>
  
  <pre><code>public delegate void FakeSave(Transaction t);
  
  Expect.Call(delegate { _dao.Save(t); }).Do( new FakeSave(delegate(Transaction t2) { t.Message = expected_msg; }));
  </code></pre>