title: Cannot use ref or out parameter in lambda expressions
body: <p>Why can't you use a ref or out parameter in a lambda expression?</p>
  
  <p>I came across the error today and found a workaround but I was still curious why this is a compile-time error.</p>
  
  <blockquote>
    <p><a href="https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs1628" rel="noreferrer">CS1628</a>: Cannot use in ref or out parameter 'parameter' inside an anonymous method, lambda expression, or query expression</p>
  </blockquote>
  
  <p>Here's a simple example:</p>
  
  <pre><code>private void Foo()
  {
      int value;
      Bar(out value);
  }
  
  private void Bar(out int value)
  {
      value = 3;
      int[] array = { 1, 2, 3, 4, 5 };
      int newValue = array.Where(a =&gt; a == value).First();
  }
  </code></pre>