C# LINQ Query to Sum Data Groupby Column? -


i have data view contains date column , power column. filling data view xml file particular link , want sum power column group "date". use linq query it:

var query = row in _hdt.asenumerable()         group row row.field<int>("date") grp         orderby grp.key         select new         {         date = grp.key,         sum = grp.sum(r => r.field<decimal>("kw"))         };          foreach (var grp in query)         {         console.writeline("{0}\t{1}", grp.id, grp.sum);         }         } 

but getting errors:

error   1   invalid token 'return' in class, struct, or interface member declaration     error   2   invalid token ';' in class, struct, or interface member declaration  error   3   expected class, delegate, enum, interface, or struct      error   4   expected class, delegate, enum, interface, or struct      error   5   expected class, delegate, enum, interface, or struct      error   6   identifier expected c:\documents , settings\administrator.musewerx- error   7   expected class, delegate, enum, interface, or struct      error   8   expected class, delegate, enum, interface, or struct      error   9   namespace not directly contain members such fields or methods  error   10  type or namespace definition, or end-of-file expected    

i hope replies.

the problem not linq query incorrect placing of braces.

apparently, compiler decided return statement right inside of class declaration. of course can't return class, can return method.

i can't tell problem right away because posted piece of code, noticed there 2 closing } instead of 1 matching foreach—could reason compiler thought method over?


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -