In this question, I saw an anonymous type expression with an unknown syntax:
new { MyObjectID = g.Key, totalSum }
At first I thought that this ( , totalSum }
) is a syntax error, because the key is not specified, but it compiles and works in C # 3.0. I checked this syntax in LINQPad (2.x -> C # 3):
var y = ":-)"; var q = new { Y = y, y, y.Length, }; q.Dump();
Result:
(anon type) { Y = ":-)", y = ":-)", Length = 3 }
Where in the specification is this syntax specified? (Responses should include the applicable link and related excerpt).
And, more subjectively (feel free to answer), is this a good syntax / short cut to omit the keys? I did not use it until I knew about it, and I am not very in love with this syntactic sugar.
user166390
source share