Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does VB.NET 2010 support arrays of anonymous objects?

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?

like image 461
royco Avatar asked Sep 26 '10 19:09

royco


People also ask

What objects does Visual Basic work with?

Microsoft Visual Basic is an object-oriented programming language .

What is the use of anonymous object?

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.

What keyword do you use to declare an anonymous type?

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.


1 Answers

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

like image 156
Matthew Manela Avatar answered Oct 06 '22 09:10

Matthew Manela