0

Here's the simple scenario:

   var q = from i in icdPatientList
                        group i by i.PatientId into grp
                        select new
                        {
                            Key = grp.Key,
                            //trailing comma causes no compile-time error
                            Count = grp.Count(),
                        };
                foreach (var item in q)
                {
                    //simple columns + counts
                    Console.WriteLine(item.Key + " " + item.Count);

                }

Why is it that in the projection having a trailing comma with nothing after it does not cause a compile-time error? Having two commas does, and of course having none works perfect as well.

wootscootinboogie
  • 8,461
  • 33
  • 112
  • 197
  • @Moo-Juice that certainly looks like that case. I didn't know if it was a LINQ-specific deal or not. – wootscootinboogie Mar 20 '14 at 13:59
  • It's not LINQ query syntax, it's just query syntax. The query syntax is entirely separate from LINQ. Next, this behavior has nothing to do with query syntax, it is a question about creating anonymous types (which is also separate from LINQ). Finally, the proposed duplicate isn't a duplicate, because anonymous types and enumeration definitions, while they both have this behavior, are two different things. – Servy Mar 20 '14 at 14:02
  • @Servy: very true on all counts. Voting to reopen. Though I suspect the answer may be very similar in terms of "this is how the spec defines it to work", just with a reference to a different part of the spec. – Chris Mar 20 '14 at 14:05
  • It seems like the consensus is "allow a trailing comma because when I comment out a line and there's a trailing comma I don't want the compiler to complain", which is a perfectly reasonable and succint answer. – wootscootinboogie Mar 20 '14 at 14:07

0 Answers0