views:

87

answers:

1

In C#, one can create an array of anonymous objects with new []. This was not supported in earlier versions of VB.NET, but a comment by Chris Dwyer in another StackOverflow post suggests to me that it might be supported in VB.NET 2010. I haven't been able to confirm this though.

Does VB.NET 2010 support arrays of anonymous objects?

+6  A: 

Yes it does. You can write one like this:

Dim values = {New With {.First = "Matt"}, New With {.First = "Mallory"}}

Updated: I removed the not needed () after values as pointed out by Ahmad Mageed

Matthew Manela
Thanks for your response. I probably was unclear in my original question. `Dim values()` is different from C#'s `new []`, right?
Slack
@Matthew you can use `Dim values` without the `()`.
Ahmad Mageed
@Slack C#'s `new[]` would be equivalent to the first and last curly braces that indicate an array of items in VB.NET. VB.NET's `Dim values` would be `var values` in C#.
Ahmad Mageed
Thanks guys. I get it now. C#'s `new []` is just handled by `{ }` in VB.NET. Was this the case prior to VB.NET 2010?
Slack