Invalid anonymous type member declarator

后端 未结 1 1871
离开以前
离开以前 2020-12-01 10:20

I have a problem with the following code which should work, according to this MSDN Forums post.

using System;
using System.Collections.Generic;
using System.         


        
1条回答
  •  旧时难觅i
    2020-12-01 10:57

    You have to name the property used to store Sum method result:

    select new { g.Key.empid, g.Key.weekending, Sum = g.Sum(s=>s.hours)};
    

    Compiler can't infer the property name when you're assigning the value from expression:

    Anonymous Types (C# Programming Guide)

    You must provide a name for a property that is being initialized with an expression (...)

    0 讨论(0)
提交回复
热议问题