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

178 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 answers

1
Dylan Nicholson On BEST ANSWER

You're missing the 'new':

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