title: Use of Lambda Expression as parameter
body: <p>I read a piece of code and get confused. It comes from a method of a class:</p>
  
  <pre><code>public ResponseType Cancel(RequestType request)
  {
      return Processor.Execute&lt;RequestType , ResponseType&gt;(
          context =&gt;
          {
              Services.Cancel(Convertor.ToBusiness(request,  context.GetUid()));
          },
          request);
  }
  </code></pre>
  
  <p>Firstly I didn't know how the <strong>context</strong> in the Lambda Expression is passed in. I mean, where the context is coming from. The <strong>Cancel(RequestType request)</strong> method's parameter list didn't provide it.
  The Processor class provides the of Execute implementation as:</p>
  
  <pre><code>public static class Processor
  {
     public static TResponse Execute&lt;TRequest, TResponse&gt;(ProcessProc proc, TRequest request)
            where TRequest : class
            where TResponse : class{......}
  
     //Processor::ProcessProc is a delegate:
     public delegate object ProcessProc(ServiceContext context); 
  }
  </code></pre>
  
  <p>Secondly, I didn't know the goodness of the <strong>where TRequest : class</strong>, I checked the msdn document that the <em>where-class</em> is to ensure the TRequest to be a reference type, is that right?</p>
  
  <p>Thanks to Alex. While still something not understand:
  For <strong>where TRequest : class</strong>: If I'm writing this piece of code, I won't be aware of adding this <em>where-class</em>. If an argument of wrong type is passed in, the compiler will complain for that I believe. So what's the meaning of using that?<br>
  It seems the <strong>context</strong> hides somewhere I didn't know yet. I verified the class Processor's definition, which didn't inherit from any other class, only contains several methods and two delegates definition, no other data or property. The code can be compiled and run through successfully. I do doubt the readability of the introducing of Lambda-ex as parameter. It's ambiguous to understand which one should be used as argument of <strong>context</strong>, how compiler can figure it out? 
  The following are examples I found on msdn:
  ex1:</p>
  
  <pre><code>delegate int del(int i);
  static void Main(string[] args)
  {
      del myDelegate = x =&gt; x * x;
      int j = myDelegate(5); //x=5, easy to understand
  }
  </code></pre>
  
  <p>ex2:</p>
  
  <pre><code>int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
  int oddNumbers = numbers.Count(n =&gt; n % 2 == 1);
  </code></pre>
  
  <p>ex2 is not straightforward as ex1, a bit less readibility to me who transferred from c++.   </p>
  
  <p>Added: Is there any possibility for the <strong>context</strong> coming from <strong>RequestType request</strong> ?    <strong>RequestType</strong> is a very large and <strong>partial</strong> class, not easy to find the complete definition. </p>
  
  <p>I found where the <strong>context</strong> is assigned at last, very very deep in <strong>ProcessProc</strong>'s factory's implementation, there the delegate is executed and the <strong>context</strong> get a value. I didn't dig deep enough how the delegate is acctually executed. So this thread is of no much value. It's nearly impossible for anyone to guess the answer without seeing all the code. Thank all very much anyway.</p>