title: Linq statement: Inner function call conflicts with enclosing method name
body: <p>Cryptic title, but I will start with the code that poses the problem and clarify afterwards:</p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>Public ReadOnly Property Max As Double
      Get
          Dim res = (From a As Double() In Values Select a.Max).Max
          Return res
      End Get
  End Property
  </code></pre>
  
  <p><code>Values</code> is a jagged array of double,</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Values()() As Double
  </code></pre>
  
  <p>that is initialized elsewhere. I want to use Linq to extract the overall maximum value.
  The code above gives the following exception for the first <code>.Max</code>:</p>
  
  <blockquote>
    <p>BC30978   Range variable 'Max' hides a variable in an enclosing block or
    a range variable previously defined in the query
    expression.</p>
  </blockquote>
  
  <p>If I change the Property name to something else like <code>GetMaximum</code> the error disappears. </p>
  
  <p><strong>Why can't I call the <code>.Max</code> function for the <code>Double()</code> variable <code>a</code> that is selected from my jagged array? What does that call has to do in the slightest with the name of the method it is in?</strong></p>
  
  <p>I am using Visual Studio Community 2015 on Windows 8.1.
  Both answers in VB.NET or C# are much appreciated.</p>
  
  <h2>Workarounds</h2>
  
  <p>As a workaround I can for example do the following:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Function GetMax(a As Double()) As Double
      Return a.Max
  End Function
  Public ReadOnly Property Max As Double
      Get
          Dim res = (From a As Double() In mvalues Select GetMax(a)).Max
          Return res
      End Get
  End Property
  </code></pre>
  
  <p>No error there, so only the inner <code>.Max</code> is responsible for the error.</p>
  
  <p>As mentioned earlier, that also works:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public ReadOnly Property GetMax As Double
      Get
          Dim res = (From a As Double() In Values Select a.Max).Max
          Return res
      End Get
  End Property
  </code></pre>
  
  <p>So it is a conflict between the first <code>.Max</code> and the property name.</p>