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?
Microsoft Visual Basic is an object-oriented programming language .
Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. The type name is generated by the compiler and is not available at the source code level. The type of each property is inferred by the compiler.
Essentially an anonymous type is a reference type and can be defined using the var keyword. You can have one or more properties in an anonymous type but all of them are read-only.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With