Is it possible to create anonymous object with child as object as well in C#?

196 Views Asked by At

I want to create anonymous object in C#, and some its child is also object. Is it possible to do that in C#? (PS. I got some hint error for the following code)

var o = new { age = 123, child = { name = "asdffff"} };
1

There are 1 best solutions below

1
On BEST ANSWER

You're missing the 'new':

var o = new { age = 123, child = new { name = "asdffff"} };