title: Settings variable values in a Moq Callback() call
body: <p>I think I may be a bit confused on the syntax of the Moq Callback methods. When I try to do something like this:</p>
  
  <pre><code>IFilter filter = new Filter();
  List&lt;IFoo&gt; objects = new List&lt;IFoo&gt; { new Foo(), new Foo() };  
  
  IQueryable myFilteredFoos = null;
  mockObject.Setup(m =&gt; m.GetByFilter(It.IsAny&lt;IFilter&gt;()))
     .Callback( (IFilter filter) =&gt; myFilteredFoos = filter.FilterCollection(objects))
     .Returns(myFilteredFoos.Cast&lt;IFooBar&gt;());
  </code></pre>
  
  <p>This throws a exception because <code>myFilteredFoos</code> is null during the <code>Cast&lt;IFooBar&gt;()</code> call. Is this not working as I expect? I would think <code>FilterCollection</code> would be called and then <code>myFilteredFoos</code> would be non-null and allow for the cast. </p>
  
  <p><code>FilterCollection</code> is not capable of returning a null which draws me to the conclusion it is not being called. Also, when I declare <code>myFilteredFoos</code> like this:</p>
  
  <pre><code>Queryable myFilteredFoos;
  </code></pre>
  
  <p>The Return call complains that myFilteredFoos may be used before it is initialized. </p>