title: A local or parameter named 'g' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
body: <p>I'm using Linq <code>GroupBy</code> to make groups from my result. Its ok for all of them but I'm getting a strange error when I try to group by <code>Year</code> value of the DateTime.</p>
  
  <pre><code>   switch (grouping)
           {
               case "country":
                   vix = vi.GroupBy(v =&gt; v.User.CountryId).Select(g =&gt; g.ToList()).ToList();
                   break;
               case "province":
                   vix = vi.GroupBy(v =&gt; v.User.ProvinceId).Select(g =&gt; g.ToList()).ToList();
                   break;
               case "city":
                   vix = vi.GroupBy(v =&gt; v.User.CityId).Select(g =&gt; g.ToList()).ToList();
                   break;
               case "region":
                   vix = vi.GroupBy(v =&gt; v.User.RegionId).Select(g =&gt; g.ToList()).ToList();
                   break;
               case "education":
                   vix = vi.GroupBy(v =&gt; v.User.EducationId).Select(g =&gt; g.ToList()).ToList();
                   break;
               case "job":
                   vix = vi.GroupBy(v =&gt; v.User.JobId).Select(g =&gt; g.ToList()).ToList();
                   break;
               case "gender":
                   vix = vi.GroupBy(v =&gt; v.User.Gender).Select(g =&gt; g.ToList()).ToList();
                   break;
               case "age":
                   vix = vi.GroupBy(v =&gt; v.User.BirthDate.Value.Year).Select(g =&gt; g.ToList()).ToList();
                   break;
           }
  </code></pre>
  
  <p>This is the error (Error is only for the last GroupBy which is for age):</p>
  
  <blockquote>
    <p>A local or parameter named 'g' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter</p>
  </blockquote>